/*
Copyright (c) [2019年5月1日] [吴超]
[MBT_studio] is licensed under Mulan PSL v2.
You can use this software according to the terms and conditions of the Mulan PSL v2.
You may obtain a copy of Mulan PSL v2 at:
		 http://license.coscl.org.cn/MulanPSL2
THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
See the Mulan PSL v2 for more details.
*/
#include "stdafx.h"
#include "随机数.h"

#include "../Surface.h"
#include "../面.h"
#include "引擎数据类型.h"
#include "UI/UI主题.h"
#include "面/几何模型生成.h"

#include <公共函数.h>
//#include <ppl.h>



//static std::vector<suvec2>	gui属性alloc记录;
//static std::vector<suvec2>	gui变换alloc记录;
//static std::vector<suvec2>	gui颜色alloc记录;
//static std::vector<suvec2>	gui线属性alloc记录;
//static std::vector<suvec2>	gui纹理属性alloc记录;





//static inline S_2D笔刷* f_alloc笔刷(){ return (S_2D笔刷*)malloc(sizeof(S_2D笔刷));}
//static inline S_2D笔刷* f_add笔刷(S_2D画布* s) {
//	//auto* 笔刷 = (S_2D笔刷*)malloc(sizeof(S_2D笔刷));
//	auto* 笔刷 = new S_2D笔刷;
//	(*笔刷) = {};
//	//s->m_笔刷.push_back(笔刷);
//	return 笔刷;
//}


static void f_vg_记录图元(S_2D画布* s, S_材质* 材质) {
	++s->m_绘制推进层;

	if (s->m_绘制推进层 >= s->m_surf.size()) {
		S_Surface2D face = {};
		f_initSurface2D(&face, s->m_Ctx);
		s->m_surf.push_back(face);
	}
	s->m_surf[s->m_绘制推进层].m_笔刷.m_材质 = 材质;
	//s->m_surf[s->m_绘制推进层].m_材质 = 材质;
}




void f_begin绘制2D图形(S_2D画布* s) {
	s->f_清除绘制数据();
	for (auto& s: s->m_surf) {
		f_releaseSurface2D(&s);
	}

	for (auto& s : s->m_扩展GPU参数) {
		f_clear板载缓存((S_板载缓存*)s);
	}
	for (auto& s : s->m_属性) {
		f_clear板载缓存((S_板载缓存*)s);
	}

	s->m_绘制推进层 = -1;
}

void f_end绘制2D图形(S_2D画布* s) {

}



void f_vg_记录元素(S_2D画布* s) {
	return;
}




//uint16 f_vg_gen变换(S_2D画布* s, uint32 num) {
//	S_板载缓存* mat = f_buf_create板载缓存(s->m_Ctx, sizeof(mat3X2), E_板载缓存类型::e_SSBO, 1);
//	s->m_扩展GPU参数.push_back(mat);
//	if (!num) {
//		mat->m_Size = 0;
//	}
//	return s->m_扩展GPU参数.size() - 1;
//}
//
//uint16 f_vg_gen颜色(S_2D画布* s, uint32 num) {
//	S_板载缓存* 颜色 = f_buf_create板载缓存(s->m_Ctx, sizeof(uint32), E_板载缓存类型::e_SSBO);
//	std::vector<uint32> data(DEF_Max(1, num));
//	f_buf_fill板载缓存<uint32>(颜色, data, E_板载缓存类型::e_SSBO);
//	s->m_扩展GPU参数.push_back(颜色);
//
//	if (!num) {
//		颜色->m_Size = 0;
//	}
//
//	return s->m_扩展GPU参数.size() - 1;
//}

uint16 f_vg_gen属性(S_2D画布* s) {
	S_板载缓存* 属性 = f_buf_create板载缓存(s->m_Ctx, sizeof(S_2D顶点属性), E_板载缓存类型::e_UBO, 1);

	S_2D顶点属性 p = {};
	p.m_比例 = {1,1};

	f_buf_fill板载缓存<S_2D顶点属性>(属性, { p }, E_板载缓存类型::e_UBO);
	s->m_属性.push_back(属性);

	return s->m_属性.size() - 1;
}


uint16 f_vg_gen渐变颜色(S_2D画布* s) {
	S_板载缓存* 颜色 = f_buf_create板载缓存(s->m_Ctx, sizeof(uvec2));
	f_buf_fill板载缓存<uvec2>(颜色, { {{0}, {0}, {0}, {0}} }, E_板载缓存类型::e_SSBO);
	s->m_扩展GPU参数.push_back(颜色);
	return s->m_扩展GPU参数.size() - 1;
}

uint16 f_vg_gen渐变梯度(S_2D画布* s) {
	S_板载缓存* 梯度 = f_buf_create板载缓存(s->m_Ctx, sizeof(vec2));
	f_buf_fill板载缓存<vec2>(梯度, {{0, 0}}, E_板载缓存类型::e_SSBO);
	s->m_扩展GPU参数.push_back(梯度);
	return s->m_扩展GPU参数.size() - 1;
}

uint16 f_vg_gen连接点属性(S_2D画布* s) {
	S_板载缓存* 连接点属性 = f_buf_create板载缓存(s->m_Ctx, sizeof(ivec4));
	f_buf_fill板载缓存<ivec4>(连接点属性, { {{0}, {0}, {0}, {0}} }, E_板载缓存类型::e_SSBO);
	连接点属性->m_Size = 0;
	s->m_扩展GPU参数.push_back(连接点属性);
	return s->m_扩展GPU参数.size() - 1;
}

uint16 f_vg_gen连接线变换(S_2D画布* s, uint32 num) {
	S_板载缓存* mat = f_buf_create板载缓存(s->m_Ctx, sizeof(S_连接线坐标参数));
	std::vector<S_连接线坐标参数> data(DEF_Max(1, num));
	f_buf_fill板载缓存<S_连接线坐标参数>(mat, data, E_板载缓存类型::e_SSBO);
	s->m_扩展GPU参数.push_back(mat);

	if (!num) {
		mat->m_Size = 0;
	}

	return s->m_扩展GPU参数.size() - 1;
}

S_板载缓存* f_vg_gen曲线(S_2D画布* s) {
	S_板载缓存* buf = f_buf_create板载缓存(s->m_Ctx, sizeof(S_CurvePoint), E_板载缓存类型::e_SSBO);
	S_CurvePoint data = { {}, {}, 0, 0 };
	f_buf_fill板载缓存(buf, sizeof(S_CurvePoint), 1, &data, E_板载缓存类型::e_SSBO);
	return buf;
}

S_板载缓存* f_vg_gen曲线点索引(S_2D画布* s) {
	S_板载缓存* buf = f_buf_create板载缓存(s->m_Ctx, sizeof(uint32), E_板载缓存类型::e_SSBO);
	uint32 data = 0;
	f_buf_fill板载缓存(buf, sizeof(uint32), 1, &data, E_板载缓存类型::e_SSBO);
	return buf;
}

S_板载缓存* f_vg_gen颜色256(S_2D画布* s) {
	S_板载缓存* buf = f_buf_create板载缓存(s->m_Ctx, sizeof(uint32), E_板载缓存类型::e_SSBO);
	f_buf_fill板载缓存<uint32>(buf, {{}}, E_板载缓存类型::e_SSBO);
	return buf;
}

S_板载缓存* f_vg_gen属性(S_设备环境& m_Ctx) {
	S_板载缓存* 属性 = f_buf_create板载缓存(m_Ctx, sizeof(S_2D顶点属性), E_板载缓存类型::e_UBO, 1);

	S_2D顶点属性 p = {};
	p.m_比例 = { 1,1 };
	f_buf_fill板载缓存<S_2D顶点属性>(属性, { p }, E_板载缓存类型::e_UBO);

	return 属性;
}

S_GPU内存块索引* f_vg_gen2D变换(S_2D画布* s, uint32 num) {
	S_GPU内存块索引* 块 = (S_GPU内存块索引*)malloc(sizeof(S_GPU内存块索引));
	(*块) = f_buf_alloc(S_2D画布::g凸包变换, 1);
	return 块;
}

S_GPU内存块索引* f_vg_gen2D颜色(S_2D画布* s, uint32 num) {
	S_GPU内存块索引* 块 = (S_GPU内存块索引*)malloc(sizeof(S_GPU内存块索引));
	(*块) = f_buf_alloc(S_2D画布::g凸包颜色, 1);
	return 块;
}

S_GPU内存块索引* f_vg_gen线属性a(S_2D画布* s) {
	S_GPU内存块索引* 块 = (S_GPU内存块索引*)malloc(sizeof(S_GPU内存块索引));
	(*块) = f_buf_alloc(S_2D画布::g凸包线属性, 1);
	return 块;
}

//S_GPU内存块索引* f_vg_gen纹理属性(S_设备环境& m_Ctx) {
//	S_GPU内存块索引* 块 = (S_GPU内存块索引*)malloc(sizeof(S_GPU内存块索引));
//	(*块) = f_buf_alloc(S_2D画布::g凸包纹理属性, 1);
//	return 块;
//}



S_GPU内存块索引* f_vg_gen色轮属性(S_设备环境& m_Ctx) {
	S_GPU内存块索引* 块 = (S_GPU内存块索引*)malloc(sizeof(S_GPU内存块索引));
	(*块) = f_buf_alloc(S_2D画布::g凸包色轮属性, 1);
	return 块;
}

S_GPU内存块索引* f_vg_gen渐变控制(S_设备环境& m_Ctx) {
	S_GPU内存块索引* 块 = (S_GPU内存块索引*)malloc(sizeof(S_GPU内存块索引));
	(*块) = f_buf_alloc(S_2D画布::g凸包渐变控制属性, 1);
	return 块;
}

S_GPU内存块索引* f_vg_gen渐变属性(S_设备环境& m_Ctx) {
	S_GPU内存块索引* 块 = (S_GPU内存块索引*)malloc(sizeof(S_GPU内存块索引));
	(*块) = f_buf_alloc(S_2D画布::g凸包渐变属性, 1);
	return 块;
}












uint16 f_vg_gen单色凸边形填充(S_2D画布* s, uint16 图元, uint16 变换, uint16 颜色, uint16 属性) {
	f_vg_记录图元(s, s->m_调色板->m_单色凸边形填充);
	
	auto& e = s->m_surf[s->m_绘制推进层].m_笔刷;
	{
		e.m_参数元素数量 = 5;
		e.m_参数元素 = (S_板载缓存**)calloc(5, sizeof(S_板载缓存*));
		e.m_GPU绑定位置 = (uint8*)calloc(e.m_参数元素数量, sizeof(uint8*));

		if (s->m_父级画布属性) e.m_参数元素[0] = s->m_父级画布属性;
		else e.m_参数元素[0] = s->m_属性[属性];
		e.m_参数元素[1] = s->m_扩展GPU参数[变换];
		e.m_参数元素[2] = s->m_扩展GPU参数[颜色];
		e.m_参数元素[3] = S_2D画布::m_间接绘制图元顶点;
		e.m_参数元素[4] = s->m_扩展GPU参数[图元];

		e.m_GPU绑定位置[0] = 0;
		e.m_GPU绑定位置[1] = 1;
		e.m_GPU绑定位置[2] = 2;
		e.m_GPU绑定位置[3] = 3;
		e.m_GPU绑定位置[4] = 4;

		s->m_surf[s->m_绘制推进层].m_笔刷.m_纹理参数 = 0;
		s->m_surf[s->m_绘制推进层].m_笔刷.m_纹理参数数量 = 0;
	}
	
	s->m_surf[s->m_绘制推进层].m_线宽 = 1.0;

	return s->m_绘制推进层;
}

uint16 f_vg_gen单色凸边形描边(S_2D画布* s, uint16 图元, uint16 变换, uint16 颜色, uint16 属性, float32 线宽) {
	f_vg_记录图元(s, s->m_调色板->m_单色凸边形描边);
	
	auto& e = s->m_surf[s->m_绘制推进层].m_笔刷;
	{
		e.m_参数元素数量 = 5;
		e.m_参数元素 = (S_板载缓存**)calloc(e.m_参数元素数量, sizeof(S_板载缓存*));
		e.m_GPU绑定位置 = (uint8*)calloc(e.m_参数元素数量, sizeof(uint8*));

		if (s->m_父级画布属性) e.m_参数元素[0] = s->m_父级画布属性;
		else e.m_参数元素[0] = s->m_属性[属性];
		//s->m_surf[s->m_绘制推进层].m_笔刷.m_参数元素[0] = s->m_属性[属性];
		s->m_surf[s->m_绘制推进层].m_笔刷.m_参数元素[1] = s->m_扩展GPU参数[变换];
		s->m_surf[s->m_绘制推进层].m_笔刷.m_参数元素[2] = s->m_扩展GPU参数[颜色];
		s->m_surf[s->m_绘制推进层].m_笔刷.m_参数元素[3] = S_2D画布::m_间接绘制图元顶点;
		s->m_surf[s->m_绘制推进层].m_笔刷.m_参数元素[4] = s->m_扩展GPU参数[图元];
		e.m_GPU绑定位置[0] = 0;
		e.m_GPU绑定位置[1] = 1;
		e.m_GPU绑定位置[2] = 2;
		e.m_GPU绑定位置[3] = 3;
		e.m_GPU绑定位置[4] = 4;

		s->m_surf[s->m_绘制推进层].m_笔刷.m_纹理参数 = 0;
		s->m_surf[s->m_绘制推进层].m_笔刷.m_纹理参数数量 = 0;
	}
	
	s->m_surf[s->m_绘制推进层].m_线宽 = 线宽;

	return s->m_绘制推进层;

}

uint16 f_vg_gen刻度线(S_2D画布* s, uint16 属性, float32 线宽) {
	f_vg_记录图元(s, s->m_调色板->m_刻度线);
	auto& e = s->m_surf[s->m_绘制推进层].m_笔刷;
	{
		e.m_参数元素数量 = 3;
		e.m_参数元素 = (S_板载缓存**)calloc(e.m_参数元素数量, sizeof(S_板载缓存*));
		e.m_GPU绑定位置 = (uint8*)calloc(e.m_参数元素数量, sizeof(uint8*));

		if (s->m_父级画布属性) e.m_参数元素[0] = s->m_父级画布属性;
		else e.m_参数元素[0] = s->m_属性[属性];
		
		e.m_参数元素[1] = S_2D画布::g图标变换;
		e.m_参数元素[2] = S_2D画布::g图标颜色;
		e.m_GPU绑定位置[0] = DEF_BINDING_WIDGET_PROP;
		e.m_GPU绑定位置[1] = DEF_BINDING_WIDGET_MATRIX;
		e.m_GPU绑定位置[2] = DEF_BINDING_WIDGET_Color;


		e.m_纹理参数 = 0;
		e.m_纹理参数数量 = 0;
	}
	s->m_surf[s->m_绘制推进层].m_线宽 = 线宽;


	//f_buf_gresize(s->m_surf[s->m_绘制推进层].m_顶点, (2048 * 12));
	f_buf_gresize(s->m_surf[s->m_绘制推进层].m_顶点, 4096);
	auto* v = f_buf_图元顶点_ptr(s->m_surf[s->m_绘制推进层].m_顶点);
	for (uint32 i = 0; i < 2048; ++i) {
		v[i * 2].coord = { float32(i), 0 };
		v[i * 2 + 1].coord = { float32(i), 1 };
	}
	//f_buf_push_back(s->m_surf[s->m_绘制推进层].m_顶点, v);
	return s->m_绘制推进层;
}

uint16 f_vg_gen填充凸边形(S_2D画布* s, uint16 图元, uint16 变换, uint16 颜色, uint16 属性, E_笔刷类型 笔刷类型) {
	switch (笔刷类型) {
	case e_单色填充: {
		f_vg_记录图元(s, s->m_调色板->m_单色凸边形填充);
		auto& e = s->m_surf[s->m_绘制推进层].m_笔刷;
		e.m_参数元素数量 = 5;
		e.m_参数元素 = (S_板载缓存**)calloc(5, sizeof(S_板载缓存*));
		e.m_GPU绑定位置 = (uint8*)calloc(5, sizeof(uint8*));
		//s->m_调色板->m_单色凸边形填充->m_Shader->f_alloc参数设置(&(笔刷.m_GPU参数set));
		//笔刷.m_材质 = s->m_调色板->m_单色凸边形填充;
		if (s->m_父级画布属性) e.m_参数元素[0] = s->m_父级画布属性;
		else e.m_参数元素[0] = s->m_属性[属性];
		e.m_GPU绑定位置[0] = 1;
		//s->m_surf[s->m_绘制推进层].m_笔刷.m_参数元素[0] = s->m_属性[属性];
		s->m_surf[s->m_绘制推进层].m_笔刷.m_参数元素[1] = s->m_扩展GPU参数[变换];
		e.m_GPU绑定位置[1] = 2;

		s->m_surf[s->m_绘制推进层].m_笔刷.m_参数元素[2] = s->m_扩展GPU参数[颜色];
		e.m_GPU绑定位置[2] = 3;

		s->m_surf[s->m_绘制推进层].m_笔刷.m_参数元素[3] = S_2D画布::m_间接绘制图元顶点;
		e.m_GPU绑定位置[3] = 4;

		s->m_surf[s->m_绘制推进层].m_笔刷.m_参数元素[4] = s->m_扩展GPU参数[图元];
		e.m_GPU绑定位置[4] = 5;
		break;
	}
		
	case e_单色描边: {
		f_vg_记录图元(s, s->m_调色板->m_单色凸边形描边);
		auto& e = s->m_surf[s->m_绘制推进层].m_笔刷;
		e.m_参数元素数量 = 5;
		e.m_参数元素 = (S_板载缓存**)calloc(5, sizeof(S_板载缓存*));
		e.m_GPU绑定位置 = (uint8*)calloc(5, sizeof(uint8*));

		if (s->m_父级画布属性) e.m_参数元素[0] = s->m_父级画布属性;
		else e.m_参数元素[0] = s->m_属性[属性];
		e.m_GPU绑定位置[0] = 1;
		//s->m_surf[s->m_绘制推进层].m_笔刷.m_参数元素[0] = s->m_属性[属性];
		s->m_surf[s->m_绘制推进层].m_笔刷.m_参数元素[1] = s->m_扩展GPU参数[变换];
		e.m_GPU绑定位置[1] = 2;

		s->m_surf[s->m_绘制推进层].m_笔刷.m_参数元素[2] = s->m_扩展GPU参数[颜色];
		e.m_GPU绑定位置[2] = 3;

		s->m_surf[s->m_绘制推进层].m_笔刷.m_参数元素[3] = S_2D画布::m_间接绘制图元顶点;
		e.m_GPU绑定位置[3] = 4;

		s->m_surf[s->m_绘制推进层].m_笔刷.m_参数元素[4] = s->m_扩展GPU参数[图元];
		e.m_GPU绑定位置[4] = 5;
		break;
	}
		
	case e_条纹: {
		f_vg_记录图元(s, s->m_调色板->m_条纹填充);
		auto& e = s->m_surf[s->m_绘制推进层].m_笔刷;
		e.m_参数元素数量 = 5;
		e.m_参数元素 = (S_板载缓存**)calloc(5, sizeof(S_板载缓存*));
		e.m_GPU绑定位置 = (uint8*)calloc(5, sizeof(uint8*));

		if (s->m_父级画布属性) e.m_参数元素[0] = s->m_父级画布属性;
		else e.m_参数元素[0] = s->m_属性[属性];
		e.m_GPU绑定位置[0] = 1;
		//e.m_参数元素[0] = s->m_属性[属性];
		//笔刷.m_参数元素[0]->m_GPUBinding = 1;
		e.m_参数元素[1] = s->m_扩展GPU参数[变换];
		e.m_GPU绑定位置[1] = 2;
		//笔刷.m_参数元素[1]->m_GPUBinding = 2;
		e.m_参数元素[2] = s->m_扩展GPU参数[颜色];
		e.m_GPU绑定位置[2] = 3;
		//笔刷.m_参数元素[2]->m_GPUBinding = 3;
		break;
	}
		
	default:
		break;
	}
	
	s->m_surf[s->m_绘制推进层].m_线宽 = 1.0;

	return s->m_绘制推进层;
}

S_凸边图元 f_vg_gen凸边图元(S_2D画布* s, const S_凸边图元& 链接元素) {
	S_凸边图元 图元{};

	if (链接元素.属性) {
		图元.属性 = 链接元素.属性;
		图元.链接属性 = true;
	}
	else {
		图元.属性 = f_vg_gen属性(s->m_Ctx);
		图元.链接属性 = false;
	}

	if (链接元素.变换) {
		图元.变换 = 链接元素.变换;
		图元.链接变换 = true;
	}
	else {
		图元.变换 = f_vg_gen2D变换(s);
		图元.链接变换 = false;
	}

	if (链接元素.颜色) {
		图元.颜色 = 链接元素.颜色;
		图元.链接颜色 = true;
	}
	else {
		图元.颜色 = f_vg_gen2D颜色(s);
		图元.链接颜色 = false;
	}

	if (链接元素.线属性) {
		图元.线属性 = 链接元素.线属性;
		图元.链接线属性 = true;
	}
	else {
		图元.线属性 = f_vg_gen线属性a(s);
		图元.链接线属性 = false;
	}

	return 图元;
}

//S_凸边图元 f_vg_gen凸边纹理图元(S_2D画布* s, const S_凸边图元& 链接元素) {
//	S_凸边图元 图元{};
//
//	if (链接元素.属性) {
//		图元.属性 = 链接元素.属性;
//		图元.链接属性 = true;
//	}
//	else {
//		图元.属性 = f_vg_gen属性(s->m_Ctx);
//		图元.链接属性 = false;
//	}
//
//	if (链接元素.变换) {
//		图元.变换 = 链接元素.变换;
//		图元.链接变换 = true;
//	}
//	else {
//		图元.变换 = f_vg_gen2D变换(s);
//		图元.链接变换 = false;
//	}
//
//	if (链接元素.颜色) {
//		图元.颜色 = 链接元素.颜色;
//		图元.链接颜色 = true;
//	}
//	else {
//		图元.颜色 = f_vg_gen2D颜色(s);
//		图元.链接颜色 = false;
//	}
//
//	if (链接元素.线属性) {
//		图元.线属性 = 链接元素.线属性;
//		图元.链接线属性 = true;
//	}
//	else {
//		图元.线属性 = f_vg_gen线属性a(s);
//		图元.链接线属性 = false;
//	}
//	
//	return 图元;
//}

//S_凸边图元 f_vg_gen纹理图元(S_2D画布* s, const S_凸边图元& 链接元素) {
//	S_凸边图元 图元{};
//
//	if (链接元素.属性) {
//		图元.属性 = 链接元素.属性;
//		图元.链接属性 = true;
//	}
//	else {
//		图元.属性 = f_vg_gen属性(s->m_Ctx);
//		图元.链接属性 = false;
//	}
//
//	if (链接元素.变换) {
//		图元.变换 = 链接元素.变换;
//		图元.链接变换 = true;
//	}
//	else {
//		图元.变换 = f_vg_gen2D变换(s);
//		图元.链接变换 = false;
//	}
//
//	if (链接元素.颜色) {
//		图元.颜色 = 链接元素.颜色;
//		图元.链接颜色 = true;
//	}
//	else {
//		图元.颜色 = f_vg_gen2D颜色(s);
//		图元.链接颜色 = false;
//	}
//
//	if (链接元素.纹理属性) {
//		图元.纹理属性 = 链接元素.纹理属性;
//		图元.链接纹理属性 = true;
//	}
//	else {
//		图元.纹理属性 = f_vg_gen纹理属性(s->m_Ctx);
//		图元.链接纹理属性 = false;
//	}
//
//	图元.线属性 = nullptr;
//	图元.链接线属性 = false;
//
//	return 图元;
//}

S_渐变图元 f_vg_gen渐变图元(S_2D画布* s, const S_渐变图元& 链接元素) {
	S_渐变图元 图元{};

	if (链接元素.属性) {
		图元.属性 = 链接元素.属性;
		图元.链接属性 = true;
	}
	else {
		图元.属性 = f_vg_gen属性(s->m_Ctx);
		图元.链接属性 = false;
	}

	if (链接元素.变换) {
		图元.变换 = 链接元素.变换;
		图元.链接变换 = true;
	}
	else {
		图元.变换 = f_vg_gen2D变换(s);
		图元.链接变换 = false;
	}

	if (链接元素.颜色) {
		图元.颜色 = 链接元素.颜色;
		图元.链接颜色 = true;
	}
	else {
		图元.颜色 = f_vg_gen渐变控制(s->m_Ctx);
		图元.链接颜色 = false;
	}

	if (链接元素.渐变) {
		图元.渐变 = 链接元素.渐变;
		图元.链接渐变 = true;
	}
	else {
		图元.渐变 = f_vg_gen渐变属性(s->m_Ctx);
		图元.链接渐变 = false;
	}

	//图元.层 = 0;

	return 图元;
}


uint16 f_vg_画行文本(S_2D画布* s, uint16 字体ID, uint16 变换, uint16 颜色, uint16 属性, uint16 字号, std::string 字体名称) {
	f_vg_记录图元(s, s->m_调色板->m_文本笔刷);
	auto& e = s->m_surf[s->m_绘制推进层].m_笔刷;
	{
		auto key = 字体名称 + "_" + f_整数值转字符串(字号);
		auto& tex = s->m_调色板->m_Fonts[key];

		e.m_参数元素数量 = 5;
		e.m_参数元素 = (S_板载缓存**)calloc(e.m_参数元素数量, sizeof(S_板载缓存*));
		e.m_GPU绑定位置 = (uint8*)calloc(e.m_参数元素数量, sizeof(uint8*));
		

		if (s->m_父级画布属性) e.m_参数元素[0] = s->m_父级画布属性;
		else e.m_参数元素[0] = s->m_属性[属性];
		e.m_GPU绑定位置[0] = DEF_BINDING_WIDGET_PROP;
		
		e.m_参数元素[1] = s->m_扩展GPU参数[变换];
		e.m_GPU绑定位置[1] = DEF_BINDING_WIDGET_MATRIX;

		e.m_参数元素[2] = s->m_扩展GPU参数[颜色];
		e.m_GPU绑定位置[2] = DEF_BINDING_WIDGET_Color;

		e.m_参数元素[3] = s->m_扩展GPU参数[字体ID];
		e.m_GPU绑定位置[3] = DEF_BINDING_WIDGET_TextCoordID;

		e.m_参数元素[4] = tex.m_uv偏移;
		e.m_GPU绑定位置[4] = DEF_BINDING_WIDGET_TextCoord;


		e.m_纹理参数 = (S_纹理**)calloc(1, sizeof(S_纹理*));
		//e.m_纹理参数数量 = 1;
		e.m_纹理参数[0] = tex.m_Tex;
		if (e.m_纹理参数[0]) {
			e.m_纹理参数数量 = 1;
		}
		else e.m_纹理参数数量 = 0;

		s->m_surf[s->m_绘制推进层].m_纹理 = key;
	}

	return s->m_绘制推进层;
}

uint16 f_vg_画行文本(S_2D画布* s, S_板载缓存* 字ID, S_板载缓存* 变换, S_板载缓存* 颜色, uint16 属性, uint16 字号, std::string 字体名称) {
	f_vg_记录图元(s, s->m_调色板->m_文本笔刷);
	auto& e = s->m_surf[s->m_绘制推进层].m_笔刷;
	{
		auto key = 字体名称 + "_" + f_整数值转字符串(字号);
		auto& tex = s->m_调色板->m_Fonts[key];

		e.m_参数元素数量 = 5;
		e.m_参数元素 = (S_板载缓存**)calloc(e.m_参数元素数量, sizeof(S_板载缓存*));
		e.m_GPU绑定位置 = (uint8*)calloc(e.m_参数元素数量, sizeof(uint8*));


		if (s->m_父级画布属性) e.m_参数元素[0] = s->m_父级画布属性;
		else e.m_参数元素[0] = s->m_属性[属性];
		e.m_GPU绑定位置[0] = DEF_BINDING_WIDGET_PROP;

		e.m_参数元素[1] = 变换;
		e.m_GPU绑定位置[1] = DEF_BINDING_WIDGET_MATRIX;

		e.m_参数元素[2] = 颜色;
		e.m_GPU绑定位置[2] = DEF_BINDING_WIDGET_Color;

		e.m_参数元素[3] = 字ID;
		e.m_GPU绑定位置[3] = DEF_BINDING_WIDGET_TextCoordID;

		e.m_参数元素[4] = tex.m_uv偏移;
		e.m_GPU绑定位置[4] = DEF_BINDING_WIDGET_TextCoord;


		e.m_纹理参数 = (S_纹理**)calloc(1, sizeof(S_纹理*));
		//e.m_纹理参数数量 = 1;
		e.m_纹理参数[0] = tex.m_Tex;
		if (e.m_纹理参数[0]) {
			e.m_纹理参数数量 = 1;
		}
		else e.m_纹理参数数量 = 0;

		s->m_surf[s->m_绘制推进层].m_纹理 = key;
	}

	return s->m_绘制推进层;
}

uint16 f_vg_画间接凸边形(S_2D画布* s, S_凸边图元& 图元, E_填充模式 模式, float32 线宽) {
	
	switch (模式) {
	case e_条纹:
	case E_填充模式::e_填充面: {
		f_vg_记录图元(s, s->m_调色板->m_间接单色填充);
		auto& e = s->m_surf[s->m_绘制推进层].m_笔刷;

		e.m_参数元素数量 = 3;
		e.m_参数元素 = (S_板载缓存**)calloc(3, sizeof(S_板载缓存*));
		e.m_GPU绑定位置 = (uint8*)calloc(3, sizeof(uint8));
		
		if (s->m_父级画布属性) e.m_参数元素[0] = s->m_父级画布属性;
		else e.m_参数元素[0] = 图元.属性;
		e.m_GPU绑定位置[0] = DEF_BINDING_WIDGET_PROP;
		
		e.m_参数元素[1] = S_2D画布::g凸包变换;
		e.m_GPU绑定位置[1] = DEF_BINDING_WIDGET_MATRIX;

		e.m_参数元素[2] = S_2D画布::g凸包颜色;
		e.m_GPU绑定位置[2] = DEF_BINDING_WIDGET_Color;


		e.m_纹理参数 = nullptr;
		e.m_纹理参数数量 = 0;
		break;
	}
		
	case E_填充模式::e_填充线: {
		f_vg_记录图元(s, s->m_调色板->m_间接单色描边);
		auto& e = s->m_surf[s->m_绘制推进层].m_笔刷;

		e.m_参数元素数量 = 4;
		e.m_参数元素 = (S_板载缓存**)calloc(e.m_参数元素数量, sizeof(S_板载缓存*));
		e.m_GPU绑定位置 = (uint8*)calloc(e.m_参数元素数量, sizeof(uint8));

		if (s->m_父级画布属性) e.m_参数元素[0] = s->m_父级画布属性;
		else e.m_参数元素[0] = 图元.属性;
		e.m_GPU绑定位置[0] = DEF_BINDING_WIDGET_PROP;
		
		e.m_参数元素[1] = S_2D画布::g凸包变换;
		e.m_GPU绑定位置[1] = DEF_BINDING_WIDGET_MATRIX;

		e.m_参数元素[2] = S_2D画布::g凸包颜色;
		e.m_GPU绑定位置[2] = DEF_BINDING_WIDGET_Color;

		e.m_参数元素[3] = S_2D画布::g凸包线属性;
		e.m_GPU绑定位置[3] = DEF_BINDING_WIDGET_LineProp;


		e.m_纹理参数 = nullptr;
		e.m_纹理参数数量 = 0;
		break;
	}

	}
	
	s->m_surf[s->m_绘制推进层].m_线宽 = 线宽;
	图元.层 = s->m_绘制推进层;

	return s->m_绘制推进层;
}

uint16 f_vg_画园公切线链接线(S_2D画布* s, uint16 属性, float32 线宽) {
	f_vg_记录图元(s, s->m_调色板->m_公切园链接线);
	auto& e = s->m_surf[s->m_绘制推进层].m_笔刷;

	e.m_参数元素数量 = 2;
	e.m_参数元素 = (S_板载缓存**)calloc(e.m_参数元素数量, sizeof(S_板载缓存*));
	e.m_GPU绑定位置 = (uint8*)calloc(e.m_参数元素数量, sizeof(uint8));

	if (s->m_父级画布属性) e.m_参数元素[0] = s->m_父级画布属性;
	else e.m_参数元素[0] = s->m_属性[属性];
	e.m_GPU绑定位置[0] = DEF_BINDING_WIDGET_PROP;

	e.m_参数元素[1] = S_2D画布::g线段;
	e.m_GPU绑定位置[1] = DEF_BINDING_WIDGET_CurvePoint;


	e.m_纹理参数 = nullptr;
	e.m_纹理参数数量 = 0;

	s->m_surf[s->m_绘制推进层].m_顶点数量 = 1;
	s->m_surf[s->m_绘制推进层].m_线宽 = 线宽;

	return s->m_绘制推进层;
}

uint16 f_vg_画条纹纹理(S_2D画布* s, S_凸边图元& 图元, E_填充模式 模式) {
	f_vg_记录图元(s, s->m_调色板->m_条纹填充);
	auto& e = s->m_surf[s->m_绘制推进层].m_笔刷;
	{
		e.m_参数元素数量 = 4;
		e.m_参数元素 = (S_板载缓存**)calloc(e.m_参数元素数量, sizeof(S_板载缓存*));
		e.m_GPU绑定位置 = (uint8*)calloc(e.m_参数元素数量, sizeof(uint8));

		if (s->m_父级画布属性) e.m_参数元素[0] = s->m_父级画布属性;
		else e.m_参数元素[0] = 图元.属性;
		e.m_GPU绑定位置[0] = DEF_BINDING_WIDGET_PROP;
		
		e.m_参数元素[1] = S_2D画布::g凸包变换;
		e.m_GPU绑定位置[1] = DEF_BINDING_WIDGET_MATRIX;
		e.m_参数元素[2] = S_2D画布::g凸包颜色;
		e.m_GPU绑定位置[2] = DEF_BINDING_WIDGET_Color;
		e.m_参数元素[3] = S_2D画布::g凸包线属性;
		e.m_GPU绑定位置[3] = DEF_BINDING_WIDGET_LineProp;
	}

	图元.层 = s->m_绘制推进层;
	return s->m_绘制推进层;
}

uint16 f_vg_画色轮(S_2D画布* s, S_凸边图元& 图元) {
	f_vg_记录图元(s, s->m_调色板->m_色轮);
	auto& e = s->m_surf[s->m_绘制推进层].m_笔刷;
	{
		e.m_参数元素数量 = 3;
		e.m_参数元素 = (S_板载缓存**)calloc(e.m_参数元素数量, sizeof(S_板载缓存*));
		e.m_GPU绑定位置 = (uint8*)calloc(e.m_参数元素数量, sizeof(uint8));

		if (s->m_父级画布属性) e.m_参数元素[0] = s->m_父级画布属性;
		else e.m_参数元素[0] = 图元.属性;
		e.m_GPU绑定位置[0] = DEF_BINDING_WIDGET_PROP;

		e.m_参数元素[1] = S_2D画布::g凸包变换;
		e.m_GPU绑定位置[1] = DEF_BINDING_WIDGET_MATRIX;
		e.m_参数元素[2] = S_2D画布::g凸包颜色;
		e.m_GPU绑定位置[2] = DEF_BINDING_WIDGET_Color;
		//e.m_参数元素[3] = S_2D画布::g凸包线属性;
		//e.m_GPU绑定位置[3] = DEF_BINDING_WIDGET_LineProp;
	}

	图元.层 = s->m_绘制推进层;
	return s->m_绘制推进层;
}

uint16 f_vg_画渐变(S_2D画布* s, S_凸边图元& 图元) {
	f_vg_记录图元(s, s->m_调色板->m_渐变);
	auto& e = s->m_surf[s->m_绘制推进层].m_笔刷;
	{
		e.m_参数元素数量 = 4;
		e.m_参数元素 = (S_板载缓存**)calloc(e.m_参数元素数量, sizeof(S_板载缓存*));
		e.m_GPU绑定位置 = (uint8*)calloc(e.m_参数元素数量, sizeof(uint8));

		if (s->m_父级画布属性) e.m_参数元素[0] = s->m_父级画布属性;
		else e.m_参数元素[0] = 图元.属性;
		e.m_GPU绑定位置[0] = DEF_BINDING_WIDGET_PROP;

		e.m_参数元素[1] = S_2D画布::g凸包变换;
		e.m_GPU绑定位置[1] = DEF_BINDING_WIDGET_MATRIX;

		e.m_参数元素[2] = S_2D画布::g凸包颜色;
		e.m_GPU绑定位置[2] = DEF_BINDING_WIDGET_Color;

		e.m_参数元素[3] = S_2D画布::g凸包线属性;
		e.m_GPU绑定位置[3] = DEF_BINDING_WIDGET_LineProp;
	}

	图元.层 = s->m_绘制推进层;
	return s->m_绘制推进层;
}


uint16 f_vg_画动态线(S_2D画布* s, uint16 属性, float32 线宽) {
	f_vg_记录图元(s, s->m_调色板->m_动态线);
	auto& e = s->m_surf[s->m_绘制推进层].m_笔刷;
	{
		e.m_参数元素 = (S_板载缓存**)calloc(3, sizeof(S_板载缓存*));
		e.m_GPU绑定位置 = (uint8*)calloc(3, sizeof(uint8));
		e.m_参数元素数量 = 3;


		if (s->m_父级画布属性) e.m_参数元素[0] = s->m_父级画布属性;
		else e.m_参数元素[0] = s->m_属性[属性];
		e.m_GPU绑定位置[0] = DEF_BINDING_WIDGET_PROP;
		e.m_参数元素[1] = S_2D画布::g图标变换;
		e.m_GPU绑定位置[1] = DEF_BINDING_WIDGET_MATRIX;
		e.m_参数元素[2] = S_2D画布::g图标颜色;
		e.m_GPU绑定位置[2] = DEF_BINDING_WIDGET_Color;


		e.m_纹理参数 = nullptr;
		e.m_纹理参数数量 = 0;
	}
	s->m_surf[s->m_绘制推进层].m_线宽 = 线宽;
	s->m_surf[s->m_绘制推进层].m_顶点数量 = 1;
	
	return s->m_绘制推进层;
}

uint16 f_vg_画网格刻度线(S_2D画布* s, uint16 属性, float32 线宽) {
	f_vg_记录图元(s, s->m_调色板->m_网格刻度线);
	auto& e = s->m_surf[s->m_绘制推进层].m_笔刷;
	{
		e.m_参数元素数量 = 3;
		e.m_参数元素 = (S_板载缓存**)calloc(e.m_参数元素数量, sizeof(S_板载缓存*));
		e.m_GPU绑定位置 = (uint8*)calloc(e.m_参数元素数量, sizeof(uint8));

		if (s->m_父级画布属性) e.m_参数元素[0] = s->m_父级画布属性;
		else e.m_参数元素[0] = s->m_属性[属性];
		
		e.m_参数元素[1] = S_2D画布::g图标变换;
		e.m_参数元素[2] = S_2D画布::g图标颜色;
		e.m_GPU绑定位置[0] = DEF_BINDING_WIDGET_PROP;
		e.m_GPU绑定位置[1] = DEF_BINDING_WIDGET_MATRIX;
		e.m_GPU绑定位置[2] = DEF_BINDING_WIDGET_Color;

		e.m_纹理参数 = 0;
		e.m_纹理参数数量 = 0;
	}
	s->m_surf[s->m_绘制推进层].m_线宽 = 线宽;

	f_buf_gresize(s->m_surf[s->m_绘制推进层].m_顶点, (2048*6));
	auto* v = f_buf_图元顶点_ptr(s->m_surf[s->m_绘制推进层].m_顶点);
	for (uint32 i = 0; i < 2048*6; ++i) {
		v[i] = { float32(i), 0 };
		v[i].coord = { float32(i), 1 };
	}
	s->m_surf[s->m_绘制推进层].m_顶点偏移 = s->m_surf[s->m_绘制推进层].m_顶点.m_Mem.m_偏移;
	s->m_surf[s->m_绘制推进层].m_顶点数量 = s->m_surf[s->m_绘制推进层].m_顶点.m_Mem.m_大小;
	
	return s->m_绘制推进层;
}

uint16 f_vg_画曲线点(S_2D画布* s, uint16 属性, S_板载缓存* 曲线点) {
	f_vg_记录图元(s, s->m_调色板->m_曲线点);
	auto& e = s->m_surf[s->m_绘制推进层].m_笔刷;
	{
		e.m_参数元素数量 = 2;
		e.m_参数元素 = (S_板载缓存**)calloc(e.m_参数元素数量, sizeof(S_板载缓存*));
		e.m_GPU绑定位置 = (uint8*)calloc(e.m_参数元素数量, sizeof(uint8));

		if (s->m_父级画布属性) e.m_参数元素[0] = s->m_父级画布属性;
		else e.m_参数元素[0] = s->m_属性[属性];
		e.m_GPU绑定位置[0] = DEF_BINDING_WIDGET_PROP;

		e.m_参数元素[1] = 曲线点;
		e.m_GPU绑定位置[1] = DEF_BINDING_WIDGET_CurvePoint;
		
		e.m_纹理参数 = 0;
		e.m_纹理参数数量 = 0;

	}
	s->m_surf[s->m_绘制推进层].m_顶点数量 = 1;
	

	return s->m_绘制推进层;
}

uint16 f_vg_画曲线(S_2D画布* s, uint16 属性, S_板载缓存* 曲线点, S_板载缓存* 曲线点ID, float32 线宽) {
	f_vg_记录图元(s, s->m_调色板->m_曲线);
	auto& e = s->m_surf[s->m_绘制推进层].m_笔刷;
	{
		e.m_参数元素数量 = 2;
		e.m_参数元素 = (S_板载缓存**)calloc(e.m_参数元素数量, sizeof(S_板载缓存*));
		e.m_GPU绑定位置 = (uint8*)calloc(e.m_参数元素数量, sizeof(uint8));

		if (s->m_父级画布属性) e.m_参数元素[0] = s->m_父级画布属性;
		else e.m_参数元素[0] = s->m_属性[属性];
		e.m_GPU绑定位置[0] = DEF_BINDING_WIDGET_PROP;
		
		e.m_参数元素[1] = 曲线点;
		e.m_GPU绑定位置[1] = DEF_BINDING_WIDGET_CurvePoint;

		//e.m_参数元素[2] = 曲线点ID;
		//e.m_GPU绑定位置[2] = DEF_BINDING_WIDGET_CurveIndex;

		e.m_纹理参数 = 0;
		e.m_纹理参数数量 = 0;
	}
	s->m_surf[s->m_绘制推进层].m_顶点数量 = 1;
	s->m_surf[s->m_绘制推进层].m_线宽 = 线宽;

	return s->m_绘制推进层;
}

uint16 f_vg_画曲线(S_2D画布* s, uint16 属性, S_板载缓存* 曲线点, float32 线宽, bool 多曲线) {
	if (多曲线) {
		f_vg_记录图元(s, s->m_调色板->m_多曲线);
	}
	else {
		f_vg_记录图元(s, s->m_调色板->m_曲线);
	}
	
	auto& e = s->m_surf[s->m_绘制推进层].m_笔刷;
	{
		e.m_参数元素数量 = 2;
		e.m_参数元素 = (S_板载缓存**)calloc(e.m_参数元素数量, sizeof(S_板载缓存*));
		e.m_GPU绑定位置 = (uint8*)calloc(e.m_参数元素数量, sizeof(uint8));

		if (s->m_父级画布属性) e.m_参数元素[0] = s->m_父级画布属性;
		else e.m_参数元素[0] = s->m_属性[属性];
		e.m_GPU绑定位置[0] = DEF_BINDING_WIDGET_PROP;

		e.m_参数元素[1] = 曲线点;
		e.m_GPU绑定位置[1] = DEF_BINDING_WIDGET_CurvePoint;

		e.m_纹理参数 = 0;
		e.m_纹理参数数量 = 0;
	}
	s->m_surf[s->m_绘制推进层].m_顶点数量 = 1;
	s->m_surf[s->m_绘制推进层].m_线宽 = 线宽;

	return s->m_绘制推进层;
}

uint16 f_vg_画噪波(S_2D画布* s, uint16 属性) {
	f_vg_记录图元(s, s->m_调色板->m_过程纹理填充);
	auto& e = s->m_surf[s->m_绘制推进层].m_笔刷;
	{
		e.m_参数元素数量 = 3;
		e.m_参数元素 = (S_板载缓存**)calloc(e.m_参数元素数量, sizeof(S_板载缓存*));
		e.m_GPU绑定位置 = (uint8*)calloc(e.m_参数元素数量, sizeof(uint8));

		if (s->m_父级画布属性) e.m_参数元素[0] = s->m_父级画布属性;
		else e.m_参数元素[0] = s->m_属性[属性];
		e.m_GPU绑定位置[0] = DEF_BINDING_WIDGET_PROP;

		e.m_参数元素[1] = S_2D画布::g纹理变换;
		e.m_GPU绑定位置[1] = DEF_BINDING_WIDGET_MATRIX;

		e.m_参数元素[2] = S_2D画布::g纹理属性;
		e.m_GPU绑定位置[2] = DEF_BINDING_WIDGET_TexProp;
	}
	return s->m_绘制推进层;
}

uint16 f_vg_画纹理(S_2D画布* s, uint16 属性, S_纹理* 纹理) {
	f_vg_记录图元(s, s->m_调色板->m_单纹理);
	auto& e = s->m_surf[s->m_绘制推进层].m_笔刷;
	{
		e.m_参数元素数量 = 2;
		e.m_参数元素 = (S_板载缓存**)calloc(e.m_参数元素数量, sizeof(S_板载缓存*));
		e.m_GPU绑定位置 = (uint8*)calloc(e.m_参数元素数量, sizeof(uint8));

		if (s->m_父级画布属性) e.m_参数元素[0] = s->m_父级画布属性;
		else e.m_参数元素[0] = s->m_属性[属性];
		e.m_GPU绑定位置[0] = DEF_BINDING_WIDGET_PROP;

		e.m_参数元素[1] = S_2D画布::g纹理变换;
		e.m_GPU绑定位置[1] = DEF_BINDING_WIDGET_MATRIX;

		e.m_纹理参数 = (S_纹理**)calloc(1, sizeof(S_纹理*));
		e.m_纹理参数[0] = 纹理;
		if (e.m_纹理参数[0]) {
			e.m_纹理参数数量 = 1;
		}
		else e.m_纹理参数数量 = 0;
	}

	return s->m_绘制推进层;
}

uint16 f_vg_画表格(S_2D画布* s, S_板载缓存* 属性) {
	f_vg_记录图元(s, s->m_调色板->m_表格线);
	auto& e = s->m_surf[s->m_绘制推进层].m_笔刷;
	{
		e.m_参数元素数量 = 3;
		e.m_参数元素 = (S_板载缓存**)calloc(e.m_参数元素数量, sizeof(S_板载缓存*));
		e.m_GPU绑定位置 = (uint8*)calloc(e.m_参数元素数量, sizeof(uint8));


		if (s->m_父级画布属性) e.m_参数元素[0] = s->m_父级画布属性;
		else e.m_参数元素[0] = 属性;
		e.m_GPU绑定位置[0] = DEF_BINDING_WIDGET_PROP;

		e.m_参数元素[1] = S_2D画布::g表格变换GPU缓存;
		e.m_GPU绑定位置[1] = DEF_BINDING_WIDGET_MATRIX;

		e.m_参数元素[2] = S_2D画布::g表格颜色GPU缓存;
		e.m_GPU绑定位置[2] = DEF_BINDING_WIDGET_Color;

	}

	return s->m_绘制推进层;
}

uint16 f_vg_画矢量线(S_2D画布* s, S_板载缓存* 属性) {
	f_vg_记录图元(s, s->m_调色板->m_矢量线);
	auto& e = s->m_surf[s->m_绘制推进层].m_笔刷;
	{
		e.m_参数元素数量 = 3;
		e.m_参数元素 = (S_板载缓存**)calloc(e.m_参数元素数量, sizeof(S_板载缓存*));
		e.m_GPU绑定位置 = (uint8*)calloc(e.m_参数元素数量, sizeof(uint8));


		if (s->m_父级画布属性) e.m_参数元素[0] = s->m_父级画布属性;
		else e.m_参数元素[0] = 属性;
		e.m_GPU绑定位置[0] = DEF_BINDING_WIDGET_PROP;

		e.m_参数元素[1] = S_2D画布::g表格变换GPU缓存;
		e.m_GPU绑定位置[1] = DEF_BINDING_WIDGET_MATRIX;

		e.m_参数元素[2] = S_2D画布::g表格颜色GPU缓存;
		e.m_GPU绑定位置[2] = DEF_BINDING_WIDGET_Color;
	}
	return s->m_绘制推进层;
}


S_2D笔刷 f_vg_gen单色阴影(S_2D画布* s, uint16 变换, uint16 颜色, uint16 属性) {
	f_vg_记录图元(s, s->m_调色板->m_边缘阴影);
	auto& e = s->m_surf[s->m_绘制推进层].m_笔刷;
	{
		e.m_参数元素数量 = 3;
		e.m_参数元素 = (S_板载缓存**)calloc(e.m_参数元素数量, sizeof(S_板载缓存*));
		e.m_GPU绑定位置 = (uint8*)calloc(e.m_参数元素数量, sizeof(uint8));
		

		if (s->m_父级画布属性) e.m_参数元素[0] = s->m_父级画布属性;
		else e.m_参数元素[0] = s->m_属性[属性];
		//e.m_参数元素[0] = s->m_属性[属性];
		e.m_参数元素[1] = s->m_扩展GPU参数[变换];
		e.m_参数元素[2] = s->m_扩展GPU参数[颜色];
		e.m_GPU绑定位置[0] = 0;
		e.m_GPU绑定位置[1] = 1;
		e.m_GPU绑定位置[2] = 2;

		e.m_纹理参数 = 0;
		e.m_纹理参数数量 = 0;
	}

	return e;
}




S_2D笔刷 f_vg_gen图像笔刷(S_2D画布* s, uint16 变换, uint16 属性, S_纹理* 纹理) {
	f_vg_记录图元(s, s->m_调色板->m_外部纹理填充);
	auto& e = s->m_surf[s->m_绘制推进层].m_笔刷;
	{
		e.m_参数元素数量 = 2;
		e.m_参数元素 = (S_板载缓存**)calloc(e.m_参数元素数量, sizeof(S_板载缓存*));
		e.m_GPU绑定位置 = (uint8*)calloc(e.m_参数元素数量, sizeof(uint8));
		

		if (s->m_父级画布属性) e.m_参数元素[0] = s->m_父级画布属性;
		else e.m_参数元素[0] = s->m_属性[属性];
		e.m_参数元素[1] = s->m_扩展GPU参数[变换];
		e.m_GPU绑定位置[0] = 0;
		e.m_GPU绑定位置[1] = 1;
		
		e.m_纹理参数 = (S_纹理**)calloc(1, sizeof(S_纹理*));
		e.m_纹理参数[0] = 纹理;
		if(纹理) {
			e.m_纹理参数数量 = 1;
		}
		else e.m_纹理参数数量 = 0;
		//e.m_纹理库对象 = &(s->m_调色板->m_ICOs[group]);
		
	}

	return e;
}

S_2D文本对象 f_vg_gen文本笔刷(S_2D画布* s, uint16 变换, uint16 颜色, uint16 属性, uint16 字体ID, std::string 字体名称, uint16 字号)  {
	f_vg_记录图元(s, s->m_调色板->m_文本笔刷);
	auto& e = s->m_surf[s->m_绘制推进层].m_笔刷;
	{
		auto key = 字体名称 + "_" + f_整数值转字符串(字号);
		auto& tex = s->m_调色板->m_Fonts[key];

		e.m_参数元素数量 = 5;
		e.m_参数元素 = (S_板载缓存**)calloc(e.m_参数元素数量, sizeof(S_板载缓存*));
		e.m_GPU绑定位置 = (uint8*)calloc(e.m_参数元素数量, sizeof(uint8));

		if (s->m_父级画布属性) e.m_参数元素[0] = s->m_父级画布属性;
		else e.m_参数元素[0] = s->m_属性[属性];
		e.m_参数元素[1] = s->m_扩展GPU参数[变换];
		e.m_参数元素[2] = s->m_扩展GPU参数[颜色];
		e.m_参数元素[3] = s->m_扩展GPU参数[字体ID];
		e.m_参数元素[4] = tex.m_uv偏移;
		e.m_GPU绑定位置[0] = 0;
		e.m_GPU绑定位置[1] = 1;
		e.m_GPU绑定位置[2] = 2;
		e.m_GPU绑定位置[3] = 3;
		e.m_GPU绑定位置[4] = 4;

		e.m_纹理参数 = (S_纹理**)calloc(1, sizeof(S_纹理*));
		//e.m_纹理参数数量 = 1;
		e.m_纹理参数[0] = tex.m_Tex;
		if (e.m_纹理参数[0]) {
			e.m_纹理参数数量 = 1;
		} else e.m_纹理参数数量 = 0;
		
		//e.m_纹理库对象 = key;
		s->m_surf[s->m_绘制推进层].m_纹理 = key;
	}

	return { &e, 字体ID };
}

S_2D笔刷 f_vg_gen文本块笔刷(S_2D画布* s, uint16 变换, uint16 颜色, uint16 属性, const S_Font& 字体) {
	f_vg_记录图元(s, s->m_调色板->m_文本块笔刷);
	auto& e = s->m_surf[s->m_绘制推进层].m_笔刷;
	{
		e.m_参数元素数量 = 4;
		e.m_参数元素 = (S_板载缓存**)calloc(e.m_参数元素数量, sizeof(S_板载缓存*));
		e.m_GPU绑定位置 = (uint8*)calloc(e.m_参数元素数量, sizeof(uint8));
		

		if (s->m_父级画布属性) e.m_参数元素[0] = s->m_父级画布属性;
		else e.m_参数元素[0] = s->m_属性[属性];
		e.m_参数元素[1] = s->m_扩展GPU参数[变换];
		e.m_参数元素[2] = s->m_扩展GPU参数[颜色];
		e.m_参数元素[3] = 字体.m_uv偏移;
		//e.m_参数元素[4] = s->m_扩展GPU参数[内部编码ID];
		e.m_GPU绑定位置[0] = 0;
		e.m_GPU绑定位置[1] = 1;
		e.m_GPU绑定位置[2] = 2;
		e.m_GPU绑定位置[3] = 3;


		e.m_纹理参数 = (S_纹理**)calloc(1, sizeof(S_纹理*));
		//e.m_纹理参数数量 = 1;
		e.m_纹理参数[0] = 字体.m_Tex;
		if (e.m_纹理参数[0]) {
			e.m_纹理参数数量 = 1;
		}
		else e.m_纹理参数数量 = 0;
	}

	return e;
}

S_2D笔刷 f_vg_gen渐变背景纹理笔刷(S_2D画布* s, uint16 属性, uint16 变换, uint16 颜色, uint16 梯度, S_纹理* 纹理) {
	f_vg_记录图元(s, s->m_调色板->m_渐变背景纹理填充);
	auto& e = s->m_surf[s->m_绘制推进层].m_笔刷;
	{
		e.m_参数元素数量 = 4;
		e.m_参数元素 = (S_板载缓存**)calloc(e.m_参数元素数量, sizeof(S_板载缓存*));
		e.m_GPU绑定位置 = (uint8*)calloc(e.m_参数元素数量, sizeof(uint8));
		

		if (s->m_父级画布属性) e.m_参数元素[0] = s->m_父级画布属性;
		else e.m_参数元素[0] = s->m_属性[属性];
		e.m_参数元素[1] = s->m_扩展GPU参数[变换];
		e.m_参数元素[2] = s->m_扩展GPU参数[颜色];
		e.m_参数元素[3] = s->m_扩展GPU参数[梯度];
		e.m_GPU绑定位置[0] = 0;
		e.m_GPU绑定位置[1] = 1;
		e.m_GPU绑定位置[2] = 2;
		e.m_GPU绑定位置[3] = 3;


		e.m_纹理参数 = (S_纹理**)calloc(1, sizeof(S_纹理*));
		//e.m_纹理参数数量 = 1;
		e.m_纹理参数[0] = 纹理;
		if (e.m_纹理参数[0]) {
			e.m_纹理参数数量 = 1;
		} else e.m_纹理参数数量 = 0;

	}

	return e;
}

S_2D笔刷 f_vg_gen棋盘格背景纹理笔刷(S_2D画布* s, uint16 属性, uint16 变换, uint16 颜色, uint16 梯度, S_纹理* 纹理) {
	f_vg_记录图元(s, s->m_调色板->m_棋盘格背景纹理填充);
	auto& e = s->m_surf[s->m_绘制推进层].m_笔刷;
	{
		e.m_参数元素数量 = 4;
		e.m_参数元素 = (S_板载缓存**)calloc(e.m_参数元素数量, sizeof(S_板载缓存*));
		e.m_GPU绑定位置 = (uint8*)calloc(e.m_参数元素数量, sizeof(uint8));
		

		if (s->m_父级画布属性) e.m_参数元素[0] = s->m_父级画布属性;
		else e.m_参数元素[0] = s->m_属性[属性];
		e.m_参数元素[1] = s->m_扩展GPU参数[变换];
		e.m_参数元素[2] = s->m_扩展GPU参数[颜色];
		e.m_参数元素[3] = s->m_扩展GPU参数[梯度];
		e.m_GPU绑定位置[0] = 0;
		e.m_GPU绑定位置[1] = 1;
		e.m_GPU绑定位置[2] = 2;
		e.m_GPU绑定位置[3] = 3;


		e.m_纹理参数 = (S_纹理**)calloc(1, sizeof(S_纹理*));
		//e.m_纹理参数数量 = 1;
		e.m_纹理参数[0] = 纹理;
		if (e.m_纹理参数[0]) {
			e.m_纹理参数数量 = 1;
		} else e.m_纹理参数数量 = 0;

	}

	return e;
}

S_2D笔刷 f_vg_gen条纹笔刷(S_2D画布* s, uint16 属性, uint16 变换, uint16 颜色) {
	f_vg_记录图元(s, s->m_调色板->m_条纹填充);
	auto& e = s->m_surf[s->m_绘制推进层].m_笔刷;
	{
		e.m_参数元素数量 = 3;
		e.m_参数元素 = (S_板载缓存**)calloc(e.m_参数元素数量, sizeof(S_板载缓存*));
		e.m_GPU绑定位置 = (uint8*)calloc(e.m_参数元素数量, sizeof(uint8));
		

		if (s->m_父级画布属性) e.m_参数元素[0] = s->m_父级画布属性;
		else e.m_参数元素[0] = s->m_属性[属性];
		e.m_参数元素[1] = s->m_扩展GPU参数[变换];
		e.m_参数元素[2] = s->m_扩展GPU参数[颜色];
		e.m_GPU绑定位置[0] = 0;
		e.m_GPU绑定位置[1] = 1;
		e.m_GPU绑定位置[2] = 2;

		e.m_纹理参数 = 0;
		e.m_纹理参数数量 = 0;
	}

	return e;
}




S_2D笔刷 f_vg_gen临时连接线笔(S_2D画布* s, uint16 变换, uint16 颜色, uint16 属性) {
	f_vg_记录图元(s, s->m_调色板->m_临时连接线笔);
	auto& e = s->m_surf[s->m_绘制推进层].m_笔刷;

	{
		e.m_参数元素 = (S_板载缓存**)calloc(3, sizeof(S_板载缓存*));
		e.m_参数元素数量 = 3;

		if (s->m_父级画布属性) e.m_参数元素[0] = s->m_父级画布属性;
		else e.m_参数元素[0] = s->m_属性[属性];
		e.m_参数元素[1] = s->m_扩展GPU参数[变换];
		e.m_参数元素[2] = s->m_扩展GPU参数[颜色];
	}
	return e;
}

S_2D笔刷 f_vg_gen连接点笔(S_2D画布* s, uint16 变换, uint16 颜色, uint16 属性, uint16 配置) {
	f_vg_记录图元(s, s->m_调色板->m_连接点笔);
	auto& e = s->m_surf[s->m_绘制推进层].m_笔刷;

	{
		e.m_参数元素 = (S_板载缓存**)calloc(4, sizeof(S_板载缓存*));
		e.m_参数元素数量 = 4;

		if (s->m_父级画布属性) e.m_参数元素[0] = s->m_父级画布属性;
		else e.m_参数元素[0] = s->m_属性[属性];
		e.m_参数元素[1] = s->m_扩展GPU参数[变换];
		e.m_参数元素[2] = s->m_扩展GPU参数[颜色];
		e.m_参数元素[3] = s->m_扩展GPU参数[配置];
	}
	
	return e;
}







uint16 f_vg_绘制矩形(S_2D画布* s, S_2D笔刷& 笔刷, const vec4& point, bool 是否填充, bool 是否开始新图元) {
	//if (是否开始新图元) f_vg_记录图元(s);
	if(是否开始新图元) f_vg_记录图元(s, 笔刷.m_材质);

	f_buf_gresize(s->m_surf[s->m_绘制推进层].m_顶点, 4);
	auto* v = f_buf_图元顶点_ptr(s->m_surf[s->m_绘制推进层].m_顶点);
	//std::vector<S_2D元素顶点> v(4);
	v[0].coord.x = point.x;
	v[2].coord.x = point.x;

	v[0].coord.y = point.y;
	v[1].coord.y = point.y;

	v[1].coord.x = point.z;
	v[3].coord.x = point.z;

	v[2].coord.y = point.w;
	v[3].coord.y = point.w;


	v[0].weights.x = 0.0;
	v[0].weights.y = 0.0;
	//C[0].z = 1.0;

	v[1].weights.x = 1.0;
	v[1].weights.y = 0.0;
	//C[1].z = 1.0;

	v[2].weights.x = 0.0;
	v[2].weights.y = 1.0;
	//C[2].z = 1.0;

	v[3].weights.x = 1.0;
	v[3].weights.y = 1.0;
	//f_buf_push_back(s->m_surf[s->m_绘制推进层].m_顶点, v);
	//s->m_surf[s->m_绘制推进层].m_顶点数量 = s->m_surf[s->m_绘制推进层].m_顶点->m_Size;
	
	return s->m_绘制推进层;
}

uint16 f_vg_绘制矩形(S_2D画布* s, S_2D笔刷& 笔刷, bool 是否填充, float32 线宽, bool 是否开始新图元) {
	//if (是否开始新图元) f_vg_记录图元(s);
	if (是否开始新图元) f_vg_记录图元(s, 笔刷.m_材质);

	
	if (是否填充) {
		f_buf_gresize(s->m_surf[s->m_绘制推进层].m_顶点, 4);
		auto* v = f_buf_图元顶点_ptr(s->m_surf[s->m_绘制推进层].m_顶点);
		//std::vector<S_2D元素顶点> v(4);
		v[0].coord.x = 0;
		v[0].coord.y = 0;

		v[1].coord.x = 1;
		v[1].coord.y = 0;

		v[2].coord.x = 0;
		v[2].coord.y = 1;
		
		v[3].coord.x = 1;
		v[3].coord.y = 1;



		v[0].weights.x = 0.0;
		v[0].weights.y = 0.0;
		//C[0].z = 1.0;
		v[1].weights.x = 1.0;
		v[1].weights.y = 0.0;
		//C[1].z = 1.0;
		v[2].weights.x = 0.0;
		v[2].weights.y = 1.0;
		//C[2].z = 1.0;
		v[3].weights.x = 1.0;
		v[3].weights.y = 1.0;

		//f_buf_push_back(s->m_surf[s->m_绘制推进层].m_顶点, v);
	} else {
		//std::vector<S_2D图元顶点> v(4);
		f_buf_gresize(s->m_surf[s->m_绘制推进层].m_顶点, 5);
		auto* v = f_buf_图元顶点_ptr(s->m_surf[s->m_绘制推进层].m_顶点);

		v[0].coord.x = 0;
		v[0].coord.y = 0;

		v[1].coord.x = 1;
		v[1].coord.y = 0;

		v[2].coord.x = 1;
		v[2].coord.y = 1;

		v[3].coord.x = 0;
		v[3].coord.y = 1;


		v[0].weights.x = 0.0;
		v[0].weights.y = 0.0;
		//C[0].z = 1.0;
		v[1].weights.x = 1.0;
		v[1].weights.y = 0.0;
		//C[1].z = 1.0;
		v[2].weights.x = 1.0;
		v[2].weights.y = 1.0;
		//C[2].z = 1.0;
		v[3].weights.x = 0.0;
		v[3].weights.y = 1.0;


		v[4] = v[3];
		//v.push_back(v.front());
		//f_buf_push_back(s->m_surf[s->m_绘制推进层].m_顶点, v);
	}

	s->m_surf[s->m_绘制推进层].m_顶点数量 = s->m_surf[s->m_绘制推进层].m_顶点.m_Mem.m_大小;
	s->m_surf[s->m_绘制推进层].m_线宽 = 线宽;
	return s->m_绘制推进层;
}

uint16 f_vg_绘制线(S_2D画布* s, const std::vector<vec2>& point, float32 线宽, bool 是否开始新图元) {
	
	f_vg_记录图元(s, s->m_调色板->m_单色描边);
	auto& e = s->m_surf[s->m_绘制推进层].m_笔刷;

	uint32 num = point.size();
	//std::vector<S_2D图元顶点> 线(num);
	f_buf_gresize(s->m_surf[s->m_绘制推进层].m_顶点, num);
	auto* v = f_buf_图元顶点_ptr(s->m_surf[s->m_绘制推进层].m_顶点);
	for (uint32 i = 0; i < num; ++i) {
		//uv[i] = { point[i].x, point[i].y, 1.0f };
		v[i].coord = point[i];
		v[i].weights = point[i];
	}
	//f_buf_push_back(s->m_surf[s->m_绘制推进层].m_顶点, 线);
	s->m_surf[s->m_绘制推进层].m_顶点数量 = s->m_surf[s->m_绘制推进层].m_顶点.m_Mem.m_大小;
	s->m_surf[s->m_绘制推进层].m_线宽 = 线宽;

	return s->m_绘制推进层;
}




inline uint32 f_构建圆角矩形顶点(std::vector<S_2D图元顶点>& vert, float32 半径, bool 是否填充) {
	uint32 num = uint32(DEF_Max(半径, 8) / 2) * 2;
	std::vector<vec2> temp(num);
	f_计算圆坐标2({ 0.0, 0.0 }, 0.5, num, temp.data());
	temp.push_back(temp.front());

	uint32 n = num / 4;
	uint32 圆角点数量 = (n + 1);

	vert.resize(圆角点数量 * 4);

	if (是否填充) {
		//vert.resize(圆角点数量 * 4);
		for (uint32 i = 0; i < 圆角点数量; ++i) {
			vert[i * 2].coord = temp[i] + 0.5;
			vert[i * 2 + 1].coord = temp[n * 4 - i] + 0.5;

			vert[i * 2 + 圆角点数量 * 2].coord = temp[n + i] + 0.5;
			vert[i * 2 + 圆角点数量 * 2 + 1].coord = temp[n * 3 - i] + 0.5;
		}


		for (uint32 i = 0; i < 圆角点数量; ++i) {
			vert[i * 2].normal = { 1.0f, 1.0f };
			vert[i * 2 + 1].normal = { 0.0, 1.0 };
			vert[i * 2 + 圆角点数量 * 2].normal = { 1.0, 0.0 };
			vert[i * 2 + 圆角点数量 * 2 + 1].normal = { 0.0,0.0 };
		}

	}
	else {
		//vert.resize(圆角点数量 * 4);
		for (uint32 i = 0; i < 4; ++i) {
			for (uint32 j = 0; j < 圆角点数量; ++j) {
				vert[i * 圆角点数量 + j].coord = temp[i * n + j] + 0.5;
			}
		}
		for (uint32 i = 0; i < 圆角点数量; ++i) {
			vert[i].weights = { 1.0f, 1.0f };
			vert[圆角点数量 + i].weights = { 1.0, 0.0 };
			vert[圆角点数量 * 2 + i].weights = { 0.0, 0.0 };
			vert[圆角点数量 * 3 + i].weights = { 0.0,1.0 };
		}

		

	}

	return 圆角点数量;
}

uint16 f_vg_绘制圆角矩形(S_2D画布* s, S_2D笔刷& 笔刷, const vec4& point, float32 半径, bool 是否填充, float32 线宽, bool 是否开始新图元) {
	//if (是否开始新图元) f_vg_记录图元(s);
	if (是否开始新图元) f_vg_记录图元(s, 笔刷.m_材质);

	uint32 num = uint32(DEF_Max(半径, 8) / 2) * 2;
	std::vector<vec2> temp(num);
	f_计算圆坐标2({0.0, 0.0}, 半径, num, temp.data());
	temp.push_back(temp.front());

	uint32 n = num / 4;
	uint32 圆角点数量 = (n + 1);
	
	//std::vector<vec2> C(圆角点数量 * 4);
	f_buf_gresize(s->m_surf[s->m_绘制推进层].m_顶点, 圆角点数量 * 4);
	auto* 圆角矩形 = f_buf_图元顶点_ptr(s->m_surf[s->m_绘制推进层].m_顶点);

	if (是否填充) {
		
		//std::vector<S_2D元素顶点> 圆角矩形(圆角点数量 * 4);

		for (uint32 i = 0; i < 圆角点数量; ++i) {
			圆角矩形[i * 2 ].coord = temp[i] + 半径;
			圆角矩形[i * 2 + 1].coord = temp[n * 4 - i] + 半径;

			圆角矩形[i * 2 + 圆角点数量 * 2].coord = temp[n + i] + 半径;
			圆角矩形[i * 2 + 圆角点数量 * 2 + 1].coord = temp[n*3 - i] + 半径;
		}
		


		for (uint32 i = 0; i < 圆角点数量; ++i) {
			圆角矩形[i * 2].weights = { 1.0f, 1.0f };
			//C[i * 2].z = 半径*2;

			圆角矩形[i * 2 + 1].weights = { 0.0, 1.0 };
			//C[i * 2 + 1].z = 半径*2;

			圆角矩形[i * 2 + 圆角点数量 * 2].weights = { 1.0, 0.0 };
			//C[i * 2 + 圆角点数量 * 2].z = 半径*2;

			圆角矩形[i * 2 + 圆角点数量 * 2 + 1].weights = { 0.0,0.0 };
			//C[i * 2 + 圆角点数量 * 2 + 1].z = 半径*2;
		}

		//f_buf_push_back(s->m_surf[s->m_绘制推进层].m_顶点, 圆角矩形);
	}
	else {
		std::vector<S_2D图元顶点> 圆角矩形(圆角点数量 * 4);

		for (uint32 i = 0; i < 4; ++i) {
			for (uint32 j = 0; j < 圆角点数量; ++j) {
				圆角矩形[i * 圆角点数量 + j].coord = temp[i*n+j] + 半径;
			}
		}
		for (uint32 i = 0; i < 圆角点数量; ++i) {
			圆角矩形[i].weights = { 1.0f, 1.0f };
			
			圆角矩形[圆角点数量 + i].weights = { 1.0, 0.0 };
			
			圆角矩形[圆角点数量 * 2 + i].weights = { 0.0, 0.0 };
			
			圆角矩形[圆角点数量 * 3 + i].weights = { 0.0,1.0 };
		}


		圆角矩形.insert(圆角矩形.begin(), 圆角矩形.back());
		圆角矩形.push_back(圆角矩形[1]);
		圆角矩形.push_back(圆角矩形[2]);

		//圆角矩形.push_back(圆角矩形[3]);
		//圆角矩形.push_back(圆角矩形[1]);
		//f_buf_push_back(s->m_surf[s->m_绘制推进层].m_顶点, 圆角矩形);
	}
	
	s->m_surf[s->m_绘制推进层].m_顶点数量 = s->m_surf[s->m_绘制推进层].m_顶点.m_Mem.m_大小;
	s->m_surf[s->m_绘制推进层].m_线宽 = 线宽;

	return s->m_绘制推进层;
}



uint16 f_vg_画连接点(S_2D画布* s, S_2D笔刷& 笔刷, bool 是否开始新图元) {
	//if (是否开始新图元) f_vg_记录图元(s);
	if (是否开始新图元) f_vg_记录图元(s, 笔刷.m_材质);
	s->m_surf[s->m_绘制推进层].m_顶点数量 = 1;
	return s->m_绘制推进层;
}


uint16 f_vg_画圆形(S_2D画布* s, S_2D笔刷& 笔刷, float32 半径, bool 是否填充, bool 是否开始新图元) {
	//if (是否开始新图元) f_vg_记录图元(s);
	if (是否开始新图元) f_vg_记录图元(s, 笔刷.m_材质);
	return s->m_绘制推进层;
}

uint16 f_vg_画单色图标(S_2D画布* s, uint16 属性, std::string 图标集) {
	f_vg_记录图元(s, s->m_调色板->m_单色图标笔刷);
	auto& e = s->m_surf[s->m_绘制推进层].m_笔刷;
	{
		e.m_参数元素数量 = 3;
		e.m_参数元素 = (S_板载缓存**)calloc(e.m_参数元素数量, sizeof(S_板载缓存*));
		e.m_GPU绑定位置 = (uint8*)calloc(e.m_参数元素数量, sizeof(uint8*));
		

		if (s->m_父级画布属性) e.m_参数元素[0] = s->m_父级画布属性;
		else e.m_参数元素[0] = s->m_属性[属性];
		e.m_GPU绑定位置[0] = DEF_BINDING_WIDGET_PROP;

		e.m_参数元素[1] = s->g图标变换;
		e.m_GPU绑定位置[1] = DEF_BINDING_WIDGET_MATRIX;

		e.m_参数元素[2] = s->g图标颜色;
		e.m_GPU绑定位置[2] = DEF_BINDING_WIDGET_Color;

		//m_纹理库对象
		e.m_纹理参数 = (S_纹理**)calloc(1, sizeof(S_纹理*));
		e.m_纹理参数[0] = s->m_调色板->m_ICOs[图标集].m_Tex;
		//e.m_纹理库对象 = 图标集;

		if (e.m_纹理参数[0]) {
			e.m_纹理参数数量 = 1;
		}
		else e.m_纹理参数数量 = 0;

		s->m_surf[s->m_绘制推进层].m_纹理 = 图标集;
		s->m_surf[s->m_绘制推进层].m_顶点数量 = 1;
	}

	return s->m_绘制推进层;
}

uint16 f_vg_画图标(S_2D画布* s, uint16 属性, std::string 图标集) {
	f_vg_记录图元(s, s->m_调色板->m_纯纹理图标笔刷);
	auto& e = s->m_surf[s->m_绘制推进层].m_笔刷;
	{
		e.m_参数元素数量 = 3;
		e.m_参数元素 = (S_板载缓存**)calloc(e.m_参数元素数量, sizeof(S_板载缓存*));
		e.m_GPU绑定位置 = (uint8*)calloc(e.m_参数元素数量, sizeof(uint8));
		

		if (s->m_父级画布属性) e.m_参数元素[0] = s->m_父级画布属性;
		else e.m_参数元素[0] = s->m_属性[属性];
		e.m_GPU绑定位置[0] = DEF_BINDING_WIDGET_PROP;

		e.m_参数元素[1] = s->g图标变换;
		e.m_GPU绑定位置[1] = DEF_BINDING_WIDGET_MATRIX;

		e.m_参数元素[2] = s->g图标颜色;
		e.m_GPU绑定位置[2] = DEF_BINDING_WIDGET_Color;

		//m_纹理库对象
		e.m_纹理参数 = (S_纹理**)calloc(1, sizeof(S_纹理*));
		e.m_纹理参数[0] = s->m_调色板->m_ICOs[图标集].m_Tex;
		//e.m_纹理库对象 = 图标集;

		if (e.m_纹理参数[0]) {
			e.m_纹理参数数量 = 1;
		}
		else e.m_纹理参数数量 = 0;

		s->m_surf[s->m_绘制推进层].m_纹理 = 图标集;
		s->m_surf[s->m_绘制推进层].m_顶点数量 = 1;
	}

	return s->m_绘制推进层;
}

uint16 f_vg_画文本(S_2D画布* s, S_2D笔刷& 笔刷, bool 是否开始新图元) {
	//if (是否开始新图元) f_vg_记录图元(s);
	//if (是否开始新图元) f_vg_记录图元(s, 笔刷.m_材质);

	//s->m_surf[s->m_绘制推进层].m_纹理 = 笔刷.m_纹理库对象;
	s->m_surf[s->m_绘制推进层].m_顶点数量 = 1;
	//s->m_surf[s->m_绘制推进层].m_着色参数 = 笔刷.m_GPU参数set;
	//s->m_surf[s->m_绘制推进层].m_Material = 笔刷.m_材质;
	return s->m_绘制推进层;
}

uint16 f_vg_画3D视口(S_2D画布* s, S_2D笔刷& 笔刷, bool 是否开始新图元) {
	if (是否开始新图元) f_vg_记录图元(s, 笔刷.m_材质);
	//if (是否开始新图元) f_vg_记录图元(s);

	//s->m_surf[s->m_绘制推进层].m_纹理 = 笔刷.m_纹理库对象;
	s->m_surf[s->m_绘制推进层].m_顶点数量 = 1;
	//s->m_surf[s->m_绘制推进层].m_着色参数 = 笔刷.m_GPU参数set;
	//s->m_surf[s->m_绘制推进层].m_Material = 笔刷.m_材质;
	return s->m_绘制推进层;
}

uint16 f_vg_画纹理面(S_2D画布* s, S_2D笔刷& 笔刷) {
	if (true) f_vg_记录图元(s, 笔刷.m_材质);
	//if (true) f_vg_记录图元(s);
	//s->m_surf[s->m_绘制推进层].m_着色参数 = 笔刷.m_GPU参数set;
	//s->m_surf[s->m_绘制推进层].m_Material = 笔刷.m_材质;
	s->m_surf[s->m_绘制推进层].m_顶点数量 = 4;
	return s->m_绘制推进层;
}



void f_vg_set绘制线(S_2D画布* s, uint16 eID, uint32 offset, const vec2& point) {
	assert(eID < s->m_surf.size());
	S_2D图元顶点 lp = { point , {0,0}, {0,0} };
	if (s->m_surf[eID].m_顶点.m_Mem.m_大小 <= offset) {
		f_buf_gresize(s->m_surf[eID].m_顶点, s->m_surf[eID].m_顶点.m_Mem.m_大小 + 1);
	}
	auto* v = f_buf_图元顶点_ptr(s->m_surf[eID].m_顶点);
	v[offset] = lp;
}

void f_vg_set绘制线(S_2D画布* s, uint16 eID, uint32 num) {
	f_buf_gresize(s->m_surf[eID].m_顶点, num);
}





void f_vg_set顶点数量(S_2D画布* s, uint16 eID, int32 num) {
	s->m_surf[eID].m_顶点数量 = num;
}

void f_vg_set实例数量(S_2D画布* s, uint16 eID, int32 num) {
	s->m_surf[eID].m_实例数量 = num;
}

void f_vg_set属性(S_2D画布* s, uint16 eID, vec2 缩放, vec2 位置偏移, int32 梯度, int32 图标间隔) {
	S_2D顶点属性 prop;
	prop.m_比例 = 缩放;
	prop.m_偏移 = 位置偏移;
	prop.m_渐变数量 = 梯度;
	prop.m_间隔 = 图标间隔;
	//if (s->m_父级画布属性) e.m_参数元素[0] = s->m_父级画布属性;
	//else e.m_参数元素[0] = s->m_属性[属性];
	f_buf_set(s->m_属性[eID], 0, prop);
}

void f_vg_set渐变梯度(S_2D画布* s, uint16 eID, vec2 dir) {
}


void f_vg_add变换实例(S_2D画布* s, uint16 eID, uint32 nums) {
	assert(eID < s->m_扩展GPU参数.size());
	std::vector<mat3X2> v(nums);
	f_buf_push_back<mat3X2>(s->m_扩展GPU参数[eID], v);
	
}

void f_vg_add单色实例(S_2D画布* s, uint16 eID, uint32 nums) {
	assert(eID < s->m_扩展GPU参数.size());
	std::vector<uint32> v(nums);
	f_buf_push_back<uint32>(s->m_扩展GPU参数[eID], v);
}

void f_vg_add遮罩实例(S_2D画布* s, uint16 eID, uint32 nums) {
	assert(eID < s->m_扩展GPU参数.size());
	std::vector<uint8> v(nums);
	f_buf_push_back<uint8>(s->m_扩展GPU参数[eID], v);
}





void f_vg_set属性(S_2D画布* s, uint16 eID, const S_2D顶点属性& 属性) {
	assert(eID < s->m_属性.size());
	f_buf_set(s->m_属性[eID], 0, 属性);
	//if (s->m_父级画布属性) e.m_参数元素[0] = s->m_父级画布属性;
	//else e.m_参数元素[0] = s->m_属性[属性];
}

void f_vg_set变换(S_2D画布* s, uint16 eID, uint32 offset, const mat3X2& mat) {
	assert(eID < s->m_扩展GPU参数.size());
	f_buf_set(s->m_扩展GPU参数[eID], offset, mat);
}

void f_vg_set单色(S_2D画布* s, uint16 eID, uint32 offset, const S_RGBA8UI color) {
	assert(eID < s->m_扩展GPU参数.size());
	f_buf_set(s->m_扩展GPU参数[eID], offset, f_PackData4X8(color));
}

void f_vg_setUV(S_2D画布* s, uint16 eID, uint16 icoID, uint32 offset, std::string iconame) {
	float32 uv = s->m_调色板->m_ICOs[s->m_surf[eID].m_纹理][iconame];
	f_buf_set(s->m_扩展GPU参数[icoID], offset, uv);
}

void f_vg_set颜色2(S_2D画布* s, uint16 eID, uint32 offset, const S_RGBA8UI colorA, const S_RGBA8UI colorB) {
	uvec2 color;
	color.x = f_PackData4X8(colorA);
	color.y = f_PackData4X8(colorB);

	f_buf_set(s->m_扩展GPU参数[eID], offset, color);
}

void f_vg_set纹理(S_2D笔刷* b, uint16 eID, S_纹理* text) {
	if (!text) {
		std::cout<<text<<std::endl;
	}
		
	b->m_纹理参数[eID] = text;
	b->m_纹理参数数量 = 1;
}

void f_vg_set纹理(S_2D画布* s, uint16 元素, uint16 eID, S_纹理* text) {
	s->m_surf[元素].m_笔刷.m_纹理参数[eID] = text;
	s->m_surf[元素].m_笔刷.m_纹理参数数量 = 1;
}

//void f_vg_set间接绘制参数(S_2D画布* s, uint16 元素, uvec2 顶点偏移数量, uint32 变换偏移, uint32 实例数量) {
//	S_VkDrawIndirectCommand ic = { 顶点偏移数量.y ,实例数量, 顶点偏移数量.x, 变换偏移 };
//	if(s->m_surf[元素].m_间接.m_Mem.m_大小 == 0) f_buf_gresize(s->m_surf[元素].m_间接, 1);
//	f_buf_Indirect_ptr(s->m_surf[元素].m_间接)[0] = ic;
//}

void f_vg_set图元(S_2D画布* s, uint16 元素, uint32 偏移, uvec2 图元) {
	f_buf_set(s->m_扩展GPU参数[元素], 偏移, 图元);
}

void f_vg_set单色(S_凸边图元& 图元, uint32 offset, const S_RGBA8UI color) {
	f_buf_UI32_at(*图元.颜色, offset) = f_PackData4X8(color);
	//f_buf_set(图元.颜色, offset, f_PackData4X8(color));
}








void f_vg_set纹理(S_2D笔刷& 笔刷, uint32 offset, S_纹理* 纹理) {
	if (!纹理) {
		std::cout << "f_vg_set纹理 : " << 纹理 << std::endl;
	}
	
	笔刷.m_纹理参数[offset] = 纹理;
	笔刷.m_纹理参数数量 = 1;
}

S_板载缓存* f_vg_get属性(S_2D画布* s, uint16 ID) {
	return s->m_属性[ID];
}




std::wstring f_vg_set行文本(S_2D画布* s, uint32 纹理集, std::wstring text, uint32 偏移, float32 width, int32* text_ptr) {
	uint32 num = text.size();
	if (!num) {
		return L"";
	}
	

	auto& 文字tex = s->m_调色板->m_Fonts[s->m_surf[纹理集].m_纹理];
	width += 文字tex.f_get字符宽度('.')*3;
	std::wstring new_text;

	float32 w = 0;
	uint32 i = 0;
	bool	是否省略 = false;
	for( ; i < num; ++i) {
		w += 文字tex.f_get字符宽度(text[i]) + S_UI主题::ui_文字间隔;

		if (w > width) {
			是否省略 = true;
			break;
		}
		new_text += text[i];
		text_ptr[偏移 + i] = text[i];
		//text_ptr[偏移 + i] = 文字tex.f_从外部编码取内部编码(text[i]);
	}
	
	if (是否省略 && i > 3) {
		i -= 3;
		//num = 文字tex.f_从外部编码取内部编码(L'.');
		num = L'.';
		text_ptr[偏移 + i] = num;
		text_ptr[偏移 + ++i] = num;
		text_ptr[偏移 + ++i] = num;
	}

	return new_text;
}

void f_vg_del文本段(S_2D画布* s, const S_2D文本对象& eID, uint32 offset, uint32 区偏移) {
	
	s->m_扩展GPU参数[eID.文本ID]->f_map();
	f_板载缓存_remove段_swapEnd<int32>(s->m_扩展GPU参数[eID.文本ID], offset * eID.区间大小, eID.区间大小);
	s->m_扩展GPU参数[eID.文本ID]->f_unmap();
}

void f_vg_resize行文本(S_2D画布* s, const S_2D文本对象& eID, uint32 num, bool 冗余)
{
	f_buf_resize(s->m_扩展GPU参数[eID.文本ID], num);
}













void f_vg_set属性间隔成员(S_2D画布* s, uint16 eID, float32 v) {
	s->m_属性[eID]->f_map();
	((S_2D顶点属性*)s->m_属性[eID]->m_mappedPtr)->m_间隔 = v;
	s->m_属性[eID]->f_unmap();
}



void f_vg_关联凸边形颜色属性(const S_2D画布* s, S_2D画布* s2, uint16 层) {
	if (s2->m_surf.size() > 层) {
		s2->m_surf[层].m_笔刷.m_参数元素[2] = s->m_surf[层].m_笔刷.m_参数元素[2];
	}
}




bool f_vg_增量添加图标(S_2D画布* s, uint16 元素ID, uint16 UVID, uint32 offset, std::string iconame) {
	//需要改进处------------!!!!!!!!!!!!!!!!!!!!!!!!!!!! 可替换成支持多线程

	float32 uv = s->m_调色板->m_ICOs[s->m_surf[元素ID].m_纹理][iconame];
	//std::cout << "uv==" << uv << std::endl;
	bool 更新GPU端 = f_resize板载缓存_Up(s->m_扩展GPU参数[UVID], offset + 1);
	f_buf_set(s->m_扩展GPU参数[UVID], offset, uv);

	return 更新GPU端;
}

void f_vg_set图标(S_2D画布* s, uint32* icoUV, uint16 元素ID, uint16 UVID, uint32 offset, std::string iconame) {
	icoUV[offset] = s->m_调色板->m_ICOs[s->m_surf[元素ID].m_纹理][iconame];
}















//废弃


//uint16 f_vg_画图标(S_2D画布* s, S_2D笔刷& 笔刷, bool 是否开始新图元) {
//	if (是否开始新图元) f_vg_记录图元(s, 笔刷.m_材质);
//	s->m_surf[s->m_绘制推进层].m_顶点数量 = 1;
//	return s->m_绘制推进层;
//	
//}



/*uint16 f_vg_绘制圆角矩形(S_2D画布* s, S_2D笔刷& 笔刷, bool 是否填充, float32 半径, float32 线宽, bool 是否开始新图元) {
	//if (是否开始新图元) f_vg_记录图元(s);
	if (是否开始新图元) f_vg_记录图元(s, 笔刷.m_材质);



	if (是否填充) {
		std::vector<S_2D元素顶点> vert;
		f_构建圆角矩形顶点(vert, 半径);
		//f_buf_push_back(s->m_surf[s->m_绘制推进层].m_顶点, vert);

		f_buf_gresize(s->m_surf[s->m_绘制推进层].m_顶点, vert.size());
		auto* 圆角矩形 = f_buf_图元顶点_ptr(s->m_surf[s->m_绘制推进层].m_顶点);
		for (uint32 i = 0; i < vert.size(); ++i) {
			圆角矩形[i].coord = vert[i].coord;
			圆角矩形[i].weights = vert[i].weights;
		}
	}
	else {
		std::vector<S_2D图元顶点> vert;
		f_构建圆角矩形顶点(vert, 半径, false);
		vert.insert(vert.begin(), vert.back());
		vert.push_back(vert[1]);
		vert.push_back(vert[2]);
		//f_buf_push_back(s->m_surf[s->m_绘制推进层].m_顶点, vert);
		f_buf_gresize(s->m_surf[s->m_绘制推进层].m_顶点, vert.size());
		auto* 圆角矩形 = f_buf_图元顶点_ptr(s->m_surf[s->m_绘制推进层].m_顶点);
		for (uint32 i = 0; i < vert.size(); ++i) {
			圆角矩形[i].coord = vert[i].coord;
			圆角矩形[i].weights = vert[i].weights;
		}
	}

	s->m_surf[s->m_绘制推进层].m_顶点数量 = s->m_surf[s->m_绘制推进层].m_顶点.m_Mem.m_大小;
	s->m_surf[s->m_绘制推进层].m_线宽 = 线宽;

	return s->m_绘制推进层;
}*/



/*uint16 f_vg_绘制半圆角矩形(S_2D画布* s, S_2D笔刷& 笔刷, float32 半径, E_方向 方向, bool 是否填充, float32 线宽) {
	//f_vg_记录图元(s);
	f_vg_记录图元(s, 笔刷.m_材质);


	//uint32 num = f_构建圆角矩形顶点(园圈点, 1.0, false);
	uint32 num = DEF_Max(3, uint32(DEF_Max(半径, 8) / 2)) * 2;

	std::vector<vec2> temp(num * 4);
	f_graph_计算圆坐标XY({ 0.5, 0.5 }, 0.5, num * 4, temp.data());


	if (是否填充) {
		std::vector<S_2D元素顶点> vert;
		switch (方向)
		{
		case E_方向::e_左: {
			//第三现象
			for (uint32 i = num; i <= num * 2; ++i) {
				vert.push_back({ temp[i], {0,1} });
			}
			//第二象限
			for (uint32 i = num * 2; i <= num * 3; ++i) {
				vert.push_back({ temp[i], {0,0} });
			}

			vert.push_back({ {1.0f, 0.0f}, {1,0} });
			vert.push_back({ {1.0f, 1.0f}, {1,1} });

			break;
		}
		case E_方向::e_右: {


			//第四象限
			for (uint32 i = 0; i <= num; ++i) {
				vert.push_back({ temp[i], {1,1} });
			}

			vert.push_back({ {0.0f, 1.0f}, {0,1} });
			vert.push_back({ {0.0f, 0.0f}, {0,0} });

			//第二现象
			for (uint32 i = num * 3; i < num * 4; ++i) {
				vert.push_back({ temp[i], {1,0} });
			}
			vert.push_back({ temp[0], {1,0} });

		}
		default:
			break;
		}

		f_buf_push_back(s->m_surf[s->m_绘制推进层].m_顶点, vert);
	}
	else {
		std::vector<S_2D图元顶点> vert;
		switch (方向)
		{
		case E_方向::e_左: {
			//第三现象
			for (uint32 i = num; i <= num * 2; ++i) {
				vert.push_back({ temp[i], {0,1} });
			}
			//第二象限
			for (uint32 i = num * 2; i <= num * 3; ++i) {
				vert.push_back({ temp[i], {0,0} });
			}

			vert.push_back({ {1.0f, 0.0f}, {0,0} });
			vert.push_back({ {1.0f, 1.0f}, {0,0} });

			break;
		}
		case E_方向::e_右: {
			//第四象限
			for (uint32 i = 0; i <= num; ++i) {
				vert.push_back({ temp[i], {1,1} });
			}

			vert.push_back({ {0.0f, 1.0f}, {0,1} });
			vert.push_back({ {0.0f, 0.0f}, {0,0} });

			//第一现象
			for (uint32 i = num * 4; i < num * 4; ++i) {
				vert.push_back({ temp[i], {1,0} });
			}
			vert.push_back({ temp[0], {1,0} });

		}
		default:
			break;
		}

		f_buf_push_back(s->m_surf[s->m_绘制推进层].m_顶点, vert);
	}


	s->m_surf[s->m_绘制推进层].m_顶点数量 = s->m_surf[s->m_绘制推进层].m_顶点->m_Size;
	s->m_surf[s->m_绘制推进层].m_线宽 = 线宽;

	return s->m_绘制推进层;
}*/






/*uint16 f_vg_绘制多单元圆角矩形(S_2D画布* s, S_2D笔刷& 笔刷, uint16 单元数量, float32 半径, E_方向 dir, float32 线宽, bool 是否开始新图元) {
	//if (是否开始新图元) f_vg_记录图元(s);
	if (是否开始新图元) f_vg_记录图元(s, 笔刷.m_材质);


	std::vector<S_2D图元顶点> vert;
	f_构建圆角矩形顶点(vert, 半径, false);
	vert.insert(vert.begin(), vert.back());
	vert.push_back(vert[1]);
	vert.push_back(vert[2]);


	auto index = range<uint16>(0, vert.size());
	//index.push_back(0xffff);
	uint16 offset = vert.size();

	float32 宽度 = (1.0) / 单元数量;
	--单元数量;
	//vert.resize(offset + 单元数量 * 2);


	for (uint16 i = 0; i < 单元数量; ++i) {
		index.push_back(0xffff);

		S_2D图元顶点 v1, v2;

		if (dir == E_方向::e_横向) {
			v1.coord.x = 宽度 * (i + 1);
			v1.coord.y = 0.0;

			v2.coord.x = 宽度 * (i + 1);
			v2.coord.y = 1.0;
		}
		else {
			v1.coord.x = 0;
			v1.coord.y = 宽度 * (i + 1);

			v2.coord.x = 1.0;
			v2.coord.y = 宽度 * (i + 1);
		}


		v1.weights = v1.coord;
		v2.weights = v2.coord;


		index.push_back(vert.size());
		vert.push_back(v1);
		index.push_back(vert.size());
		vert.push_back(v2);

	}

	f_buf_push_back(s->m_surf[s->m_绘制推进层].m_顶点, vert);
	f_buf_push_back(s->m_surf[s->m_绘制推进层].m_索引, index);

	s->m_surf[s->m_绘制推进层].m_顶点数量 = index.size();
	//s->m_surf[s->m_绘制推进层].m_着色参数 = 笔刷.m_GPU参数set;
	//s->m_surf[s->m_绘制推进层].m_Material = 笔刷.m_材质;
	s->m_surf[s->m_绘制推进层].m_线宽 = 线宽;

	return s->m_绘制推进层;
}

uint16 f_vg_绘制多单元圆角矩形(S_2D画布* s, S_2D笔刷& 笔刷, uint16 单元数量, E_方向 方向, float32 线宽) {
	//f_vg_记录图元(s);
	f_vg_记录图元(s, 笔刷.m_材质);

	std::vector<S_2D图元顶点> vert;
	std::vector<S_VkDrawIndirectCommand> Indirect(3);


	uint32 num = 6;
	std::vector<vec2> temp(num * 4);
	f_graph_计算圆坐标XY({ 0.5, 0.5 }, 0.5, num * 4, temp.data());


	//std::vector<S_2D线图元顶点> vert;
	switch (方向)
	{
	case E_方向::e_横向: {
		//================== 左边 =====================
		//第三现象
		for (uint32 i = num; i <= num * 2; ++i) {
			vert.push_back({ temp[i], {0,1}, {} });
		}
		//第二象限
		for (uint32 i = num * 2; i <= num * 3; ++i) {
			vert.push_back({ temp[i], {0,0}, {} });
		}

		vert.push_back({ {1.0f, 0.0f}, {0,0}, {} });
		vert.push_back({ {1.0f, 1.0f}, {0,0}, {} });

		Indirect[0] = { uint32(vert.size()), 1, 0, 0 };
		Indirect[0] = { uint32(vert.size()), 1, uint32(vert.size()), 0 };
		Indirect[0] = { 4, 1, uint32(vert.size()*2), 0 };



		//================= 右边 ====================
		//第四象限
		for (uint32 i = 0; i <= num; ++i) {
			vert.push_back({ temp[i], {1,1}, {} });
		}

		vert.push_back({ {0.0f, 1.0f}, {0,1}, {} });
		vert.push_back({ {0.0f, 0.0f}, {0,0}, {} });

		//第一现象
		for (uint32 i = num * 4; i < num * 4; ++i) {
			vert.push_back({ temp[i], {1,0}, {} });
		}
		vert.push_back({ temp[0], {1,0}, {} });


		//================= 中间 ===================
		vert.push_back({ {0.0f, 0.0f}, {0,0}, {} });
		vert.push_back({ {1.0f, 0.0f}, {1,0}, {} });
		vert.push_back({ {1.0f, 1.0f}, {1,1}, {} });
		vert.push_back({ {0.0f, 1.0f}, {0,1}, {} });

		break;
	}
	case E_方向::e_纵向: {

		break;
	}
	default:
		break;
	}

	f_buf_fill板载缓存(s->m_surf[s->m_绘制推进层].m_顶点, vert);
	//f_buf_push_back(s->m_surf[s->m_绘制推进层].m_顶点, vert);
	f_buf_fill板载缓存(s->m_surf[s->m_绘制推进层].m_间接, Indirect);


	//s->m_surf[s->m_绘制推进层].m_类型数量 = 3;
	s->m_surf[s->m_绘制推进层].m_顶点数量 = s->m_surf[s->m_绘制推进层].m_顶点->m_Size;

	s->m_surf[s->m_绘制推进层].m_线宽 = 线宽;
	return s->m_绘制推进层;
}*/


/*void f_vg_add绘制线(S_2D画布* s, uint16 id, vec2* point, uint32 num) {
	std::vector<S_2D图元顶点> data(num);
	for (uint32 i = 0; i < num; ++i) {
		data[i] = { point[i], {1.0f,1.0f}, {0,0} };
	}
	f_buf_push_back(s->m_surf[id].m_顶点, data);
}*/




/*inline uint32 f_构建圆角矩形顶点(std::vector<S_2D元素顶点>& vert, float32 半径) {
	uint32 num = uint32(DEF_Max(半径, 8) / 2) * 2;
	std::vector<vec2> temp(num);
	f_计算圆坐标2({ 0.0, 0.0 }, 0.5, num, temp.data());
	temp.push_back(temp.front());

	uint32 n = num / 4;
	uint32 圆角点数量 = (n + 1);

	vert.resize(圆角点数量 * 4);

	//vert.resize(圆角点数量 * 4);
	for (uint32 i = 0; i < 圆角点数量; ++i) {
		vert[i * 2].coord = temp[i] + 0.5;
		vert[i * 2 + 1].coord = temp[n * 4 - i] + 0.5;

		vert[i * 2 + 圆角点数量 * 2].coord = temp[n + i] + 0.5;
		vert[i * 2 + 圆角点数量 * 2 + 1].coord = temp[n * 3 - i] + 0.5;
	}


	for (uint32 i = 0; i < 圆角点数量; ++i) {
		vert[i * 2].weights = { 1.0f, 1.0f };
		vert[i * 2 + 1].weights = { 0.0, 1.0 };
		vert[i * 2 + 圆角点数量 * 2].weights = { 1.0, 0.0 };
		vert[i * 2 + 圆角点数量 * 2 + 1].weights = { 0.0,0.0 };
	}



	return 圆角点数量;
}*/






//uint16 f_vg_gen顶点(S_2D画布* s, uint32 num) {
//	S_板载缓存* mat = f_buf_create板载缓存(s->m_Ctx, E_板载缓存类型::e_SSBO, sizeof(mat3X2));
//	std::vector<mat3X2> data(DEF_Max(1, num));
//	f_buf_fill板载缓存<mat3X2>(mat, data, E_板载缓存类型::e_SSBO);
//	s->m_扩展GPU参数.push_back(mat);
//
//	if (!num) {
//		mat->m_Size = 0;
//	}
//
//	return s->m_扩展GPU参数.size() - 1;
//}

//uint16 f_vg_gen图元(S_2D画布* s, uint32 num) {
//	S_板载缓存* mat = f_buf_create板载缓存(s->m_Ctx, E_板载缓存类型::e_SSBO, sizeof(uvec2));
//	std::vector<uvec2> data(DEF_Max(1, num));
//	f_buf_fill板载缓存<uvec2>(mat, data, E_板载缓存类型::e_SSBO);
//	s->m_扩展GPU参数.push_back(mat);
//
//	if (!num) {
//		mat->m_Size = 0;
//	}
//
//	return s->m_扩展GPU参数.size() - 1;
//}


/*S_凸边图元 f_vg_gen凸边填充图元(S_2D画布* s, const S_凸边图元& 链接元素) {
S_凸边图元 图元;

if (链接元素.属性) {
图元.属性 = 链接元素.属性;
图元.链接属性 = true;
}
else {
图元.属性 = f_vg_gen属性(s->m_Ctx);
图元.链接属性 = false;
}

if (链接元素.变换) {
图元.变换 = 链接元素.变换;
图元.链接变换 = true;
}
else {
图元.变换 = f_vg_gen2D变换(s);
图元.链接变换 = false;
}

if (链接元素.颜色) {
图元.颜色 = 链接元素.颜色;
图元.链接颜色 = true;
}
else {
图元.颜色 = f_vg_gen2D颜色(s);
图元.链接颜色 = false;
}

图元.线属性 = nullptr;
return 图元;
}*/


/*S_GPU内存块索引* f_vg_gen2D颜色2(S_2D画布* s, uint32 num) {
S_GPU内存块索引* 块 = (S_GPU内存块索引*)malloc(sizeof(S_GPU内存块索引));
(*块) = f_buf_alloc(S_2D画布::g凸包颜色2, 1);
return 块;
}*/

/*S_板载缓存* f_vg_gen图元ID(S_2D画布* s) {
S_板载缓存* 图元 = f_buf_create板载缓存(s->m_Ctx, E_板载缓存类型::e_SSBO, sizeof(uvec2));
std::vector<uvec2> data(1);
f_buf_fill板载缓存<uvec2>(图元, data, E_板载缓存类型::e_SSBO);
s->m_扩展GPU参数.push_back(图元);

图元->m_Size = 0;

return 图元; 
}*/

/*uint16 f_vg_gen间接图元(S_2D画布* s, uint32 num)
{
S_板载缓存* 颜色 = f_create板载缓存(s->m_Ctx, sizeof(uint32));
std::vector<uint32> data(DEF_Max(1, num));
f_fill板载缓存<uint32>(颜色, data, E_板载缓存类型::e_SSBO);
s->m_扩展GPU参数.push_back(颜色);
if (!num) {
颜色->m_Size = 0;
}
return s->m_扩展GPU参数.size() - 1;
}*/

/*uint16 f_vg_gen线属性(S_2D画布* s) {
S_板载缓存* mat = f_buf_create板载缓存(s->m_Ctx, sizeof(S_线属性), E_板载缓存类型::e_SSBO);
S_线属性 data = { 0.0f, 0xffffffff, 0xffffffff };
f_buf_fill板载缓存(mat, sizeof(S_线属性), 1, &data, E_板载缓存类型::e_SSBO);
s->m_扩展GPU参数.push_back(mat);

return s->m_扩展GPU参数.size() - 1;
}*/





//S_2D笔刷 f_vg_gen图标笔刷(S_2D画布* s, uint16 变换, uint16 颜色, uint16 属性, uint16 UV, std::string group) {
//	f_vg_记录图元(s, s->m_调色板->m_单色图标笔刷);
//	auto& e = s->m_surf[s->m_绘制推进层].m_笔刷;
//	{
//		e.m_参数元素数量 = 3;
//		e.m_参数元素 = (S_板载缓存**)calloc(e.m_参数元素数量, sizeof(S_板载缓存*));
//		e.m_GPU绑定位置 = (uint8*)calloc(e.m_参数元素数量, sizeof(uint8));
//		
//		if (s->m_父级画布属性) e.m_参数元素[0] = s->m_父级画布属性;
//		else e.m_参数元素[0] = s->m_属性[属性];
//		//e.m_参数元素[0] = s->m_属性[属性];
//		e.m_参数元素[1] = s->m_扩展GPU参数[变换];
//		e.m_参数元素[2] = s->m_扩展GPU参数[颜色];
//		//e.m_参数元素[3] = s->m_扩展GPU参数[UV];
//		e.m_GPU绑定位置[0] = DEF_BINDING_WIDGET_PROP;
//		e.m_GPU绑定位置[1] = DEF_BINDING_WIDGET_MATRIX;
//		e.m_GPU绑定位置[2] = DEF_BINDING_WIDGET_Color;
//		//e.m_GPU绑定位置[3] = 3;
//
//		
//		e.m_纹理参数 = (S_纹理**)calloc(1, sizeof(S_纹理*));
//		//e.m_纹理参数数量 = 1;
//
//		e.m_纹理参数[0] = s->m_调色板->m_ICOs[group].m_Tex;
//		//e.m_纹理库对象 = group;
//		//e.m_纹理库对象 = &(s->m_调色板->m_ICOs[group]);
//		if (e.m_纹理参数[0]) {
//			e.m_纹理参数数量 = 1;
//		} else e.m_纹理参数数量 = 0;
//
//		s->m_surf[s->m_绘制推进层].m_纹理 = group;
//	}
//
//	return e;
//}

//S_2D笔刷 f_vg_gen纯纹理图标笔刷(S_2D画布* s, uint16 变换, uint16 颜色, uint16 属性, uint16 UV, std::string group) {
//	f_vg_记录图元(s, s->m_调色板->m_纯纹理图标笔刷);
//	auto& e = s->m_surf[s->m_绘制推进层].m_笔刷;
//	{
//		e.m_参数元素数量 = 3;
//		e.m_参数元素 = (S_板载缓存**)calloc(e.m_参数元素数量, sizeof(S_板载缓存*));
//		e.m_GPU绑定位置 = (uint8*)calloc(e.m_参数元素数量, sizeof(uint8));
//		
//		if (s->m_父级画布属性) e.m_参数元素[0] = s->m_父级画布属性;
//		else e.m_参数元素[0] = s->m_属性[属性];
//		e.m_GPU绑定位置[0] = DEF_BINDING_WIDGET_PROP;
//		//e.m_参数元素[0] = s->m_属性[属性];
//		e.m_参数元素[1] = s->m_扩展GPU参数[变换];
//		e.m_GPU绑定位置[1] = DEF_BINDING_WIDGET_MATRIX;
//
//		e.m_参数元素[2] = s->m_扩展GPU参数[颜色];
//		e.m_GPU绑定位置[2] = DEF_BINDING_WIDGET_Color;
//
//		//e.m_参数元素[3] = s->m_扩展GPU参数[UV];
//		//e.m_GPU绑定位置[3] = 4;
//
//
//		e.m_纹理参数 = (S_纹理**)calloc(1, sizeof(S_纹理*));
//		//e.m_纹理参数数量 = 1;
//		e.m_纹理参数[0] = s->m_调色板->m_ICOs[group].m_Tex;
//		//e.m_纹理库对象 = group;
//
//		if (e.m_纹理参数[0]) {
//			e.m_纹理参数数量 = 1;
//		} else e.m_纹理参数数量 = 0;
//
//		s->m_surf[s->m_绘制推进层].m_纹理 = group;
//	}
//	return e;
//}



